| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/android/display_android_manager.h" | 5 #include "ui/android/display_android_manager.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "jni/DisplayAndroidManager_jni.h" | 12 #include "jni/DisplayAndroidManager_jni.h" |
| 13 #include "ui/android/screen_android.h" | 13 #include "ui/android/screen_android.h" |
| 14 #include "ui/android/view_android.h" |
| 14 #include "ui/android/window_android.h" | 15 #include "ui/android/window_android.h" |
| 15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 | 19 |
| 19 using base::android::AttachCurrentThread; | 20 using base::android::AttachCurrentThread; |
| 20 using display::Display; | 21 using display::Display; |
| 21 using display::DisplayList; | 22 using display::DisplayList; |
| 22 | 23 |
| 23 void SetScreenAndroid() { | 24 void SetScreenAndroid() { |
| 24 // Do not override existing Screen. | 25 // Do not override existing Screen. |
| 25 DCHECK_EQ(display::Screen::GetScreen(), nullptr); | 26 DCHECK_EQ(display::Screen::GetScreen(), nullptr); |
| 26 | 27 |
| 27 DisplayAndroidManager* manager = new DisplayAndroidManager(); | 28 DisplayAndroidManager* manager = new DisplayAndroidManager(); |
| 28 display::Screen::SetScreenInstance(manager); | 29 display::Screen::SetScreenInstance(manager); |
| 29 | 30 |
| 30 JNIEnv* env = AttachCurrentThread(); | 31 JNIEnv* env = AttachCurrentThread(); |
| 31 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)manager); | 32 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)manager); |
| 32 } | 33 } |
| 33 | 34 |
| 34 bool RegisterScreenAndroid(JNIEnv* env) { | 35 bool RegisterScreenAndroid(JNIEnv* env) { |
| 35 return RegisterNativesImpl(env); | 36 return RegisterNativesImpl(env); |
| 36 } | 37 } |
| 37 | 38 |
| 38 DisplayAndroidManager::DisplayAndroidManager() {} | 39 DisplayAndroidManager::DisplayAndroidManager() {} |
| 39 | 40 |
| 40 DisplayAndroidManager::~DisplayAndroidManager() {} | 41 DisplayAndroidManager::~DisplayAndroidManager() {} |
| 41 | 42 |
| 42 // Screen interface. | 43 // static |
| 44 DisplayAndroidManager* DisplayAndroidManager::GetInstance() { |
| 45 return static_cast<DisplayAndroidManager*>(display::Screen::GetScreen()); |
| 46 } |
| 43 | 47 |
| 44 Display DisplayAndroidManager::GetDisplayNearestWindow( | 48 Display DisplayAndroidManager::GetDisplayNearestWindowAndroid( |
| 45 gfx::NativeView view) const { | 49 gfx::NativeWindow window) const { |
| 46 ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr; | |
| 47 if (window) { | 50 if (window) { |
| 48 DisplayList::Displays::const_iterator it = | 51 DisplayList::Displays::const_iterator it = |
| 49 display_list().FindDisplayById(window->display_id()); | 52 display_list().FindDisplayById(window->display_id()); |
| 50 if (it != display_list().displays().end()) { | 53 if (it != display_list().displays().end()) { |
| 51 return *it; | 54 return *it; |
| 52 } | 55 } |
| 53 } | 56 } |
| 54 return GetPrimaryDisplay(); | 57 return GetPrimaryDisplay(); |
| 55 } | 58 } |
| 56 | 59 |
| 60 // Screen interface. |
| 61 |
| 62 Display DisplayAndroidManager::GetDisplayNearestWindow( |
| 63 gfx::NativeView view) const { |
| 64 ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr; |
| 65 return GetDisplayNearestWindowAndroid(window); |
| 66 } |
| 67 |
| 57 // There is no notion of relative display positions on Android. | 68 // There is no notion of relative display positions on Android. |
| 58 Display DisplayAndroidManager::GetDisplayNearestPoint( | 69 Display DisplayAndroidManager::GetDisplayNearestPoint( |
| 59 const gfx::Point& point) const { | 70 const gfx::Point& point) const { |
| 60 NOTIMPLEMENTED(); | 71 NOTIMPLEMENTED(); |
| 61 return GetPrimaryDisplay(); | 72 return GetPrimaryDisplay(); |
| 62 } | 73 } |
| 63 | 74 |
| 64 // There is no notion of relative display positions on Android. | 75 // There is no notion of relative display positions on Android. |
| 65 Display DisplayAndroidManager::GetDisplayMatching( | 76 Display DisplayAndroidManager::GetDisplayMatching( |
| 66 const gfx::Rect& match_rect) const { | 77 const gfx::Rect& match_rect) const { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 122 } |
| 112 | 123 |
| 113 void DisplayAndroidManager::SetPrimaryDisplayId( | 124 void DisplayAndroidManager::SetPrimaryDisplayId( |
| 114 JNIEnv* env, | 125 JNIEnv* env, |
| 115 const base::android::JavaParamRef<jobject>& jobject, | 126 const base::android::JavaParamRef<jobject>& jobject, |
| 116 jint sdkDisplayId) { | 127 jint sdkDisplayId) { |
| 117 primary_display_id_ = sdkDisplayId; | 128 primary_display_id_ = sdkDisplayId; |
| 118 } | 129 } |
| 119 | 130 |
| 120 } // namespace ui | 131 } // namespace ui |
| OLD | NEW |