OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/android/display_android_manager.h" |
| 6 |
| 7 #include <jni.h> |
| 8 #include <map> |
| 9 |
| 10 #include "base/android/jni_android.h" |
| 11 //#include "base/macros.h" |
| 12 #include "base/stl_util.h" |
| 13 #include "jni/DisplayAndroidManager_jni.h" |
| 14 #include "ui/android/screen_android.h" |
| 15 #include "ui/android/window_android.h" |
| 16 #include "ui/display/display.h" |
| 17 |
| 18 namespace ui { |
| 19 |
| 20 using base::android::AttachCurrentThread; |
| 21 using display::Display; |
| 22 using display::DisplayObserver; |
| 23 |
| 24 display::Screen* CreateScreenAndroid() { |
| 25 // DisplayAndroidManager should be created only once. |
| 26 DCHECK(!display::Screen::GetScreen()); |
| 27 |
| 28 DisplayAndroidManager* result = new DisplayAndroidManager(); |
| 29 |
| 30 JNIEnv* env = AttachCurrentThread(); |
| 31 Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)result); |
| 32 return result; |
| 33 } |
| 34 |
| 35 bool RegisterScreenAndroid(JNIEnv* env) { |
| 36 return RegisterNativesImpl(env); |
| 37 } |
| 38 |
| 39 DisplayAndroidManager::DisplayAndroidManager() {} |
| 40 |
| 41 DisplayAndroidManager::~DisplayAndroidManager() {} |
| 42 |
| 43 // Screen interface. |
| 44 |
| 45 gfx::Point DisplayAndroidManager::GetCursorScreenPoint() { |
| 46 NOTIMPLEMENTED(); |
| 47 return gfx::Point(); |
| 48 } |
| 49 |
| 50 bool DisplayAndroidManager::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 51 NOTIMPLEMENTED(); |
| 52 return false; |
| 53 } |
| 54 |
| 55 gfx::NativeWindow DisplayAndroidManager::GetWindowAtScreenPoint( |
| 56 const gfx::Point& point) { |
| 57 NOTIMPLEMENTED(); |
| 58 return NULL; |
| 59 } |
| 60 |
| 61 int DisplayAndroidManager::GetNumDisplays() const { |
| 62 DCHECK_GE(displays_.size(), 1U); |
| 63 return displays_.size(); |
| 64 } |
| 65 |
| 66 std::vector<Display> DisplayAndroidManager::GetAllDisplays() const { |
| 67 DCHECK_GE(displays_.size(), 1U); |
| 68 |
| 69 std::vector<Display> result; |
| 70 for (const auto& display : displays_) |
| 71 result.push_back(display.second); |
| 72 |
| 73 return result; |
| 74 } |
| 75 |
| 76 Display DisplayAndroidManager::GetDisplayNearestWindow( |
| 77 gfx::NativeView view) const { |
| 78 DCHECK(view); |
| 79 ui::WindowAndroid* window = view->GetWindowAndroid(); |
| 80 |
| 81 if (window) { |
| 82 DisplayMap::const_iterator it = displays_.find(window->display_id()); |
| 83 if (it != displays_.end()) { |
| 84 return it->second; |
| 85 } |
| 86 } |
| 87 return GetPrimaryDisplay(); |
| 88 } |
| 89 |
| 90 Display DisplayAndroidManager::GetDisplayNearestPoint( |
| 91 const gfx::Point& point) const { |
| 92 NOTIMPLEMENTED(); |
| 93 return GetPrimaryDisplay(); |
| 94 } |
| 95 |
| 96 Display DisplayAndroidManager::GetDisplayMatching( |
| 97 const gfx::Rect& match_rect) const { |
| 98 NOTIMPLEMENTED(); |
| 99 return GetPrimaryDisplay(); |
| 100 } |
| 101 |
| 102 Display DisplayAndroidManager::GetPrimaryDisplay() const { |
| 103 DisplayMap::const_iterator it = displays_.find(primary_display_id_); |
| 104 // Primary display must be set before the first call to this method. |
| 105 CHECK(it != displays_.end()); |
| 106 return it->second; |
| 107 } |
| 108 |
| 109 void DisplayAndroidManager::AddObserver(DisplayObserver* observer) { |
| 110 NOTIMPLEMENTED(); |
| 111 } |
| 112 |
| 113 void DisplayAndroidManager::RemoveObserver(DisplayObserver* observer) { |
| 114 NOTIMPLEMENTED(); |
| 115 } |
| 116 |
| 117 // Methods called from Java |
| 118 |
| 119 void DisplayAndroidManager::UpdateDisplay( |
| 120 JNIEnv* env, |
| 121 const base::android::JavaParamRef<jobject>& jobject, |
| 122 jint sdkDisplayId, |
| 123 jint physicalWidth, |
| 124 jint physicalHeight, |
| 125 jint width, |
| 126 jint height, |
| 127 jfloat dipScale, |
| 128 jint rotationDegrees, |
| 129 jint bitsPerPixel, |
| 130 jint bitsPerComponent) { |
| 131 gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight); |
| 132 |
| 133 // Physical width and height might be not supported. |
| 134 if (bounds_in_pixels.IsEmpty()) |
| 135 bounds_in_pixels = gfx::Rect(width, height); |
| 136 |
| 137 const gfx::Rect bounds_in_dip = gfx::Rect( |
| 138 gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale)); |
| 139 |
| 140 display::Display display(sdkDisplayId, bounds_in_dip); |
| 141 |
| 142 display.set_device_scale_factor(dipScale); |
| 143 display.SetRotationAsDegree(rotationDegrees); |
| 144 display.set_color_depth(bitsPerPixel); |
| 145 display.set_depth_per_component(bitsPerComponent); |
| 146 display.set_is_monochrome(bitsPerComponent == 0); |
| 147 |
| 148 displays_[sdkDisplayId] = display; |
| 149 } |
| 150 |
| 151 void DisplayAndroidManager::RemoveDisplay( |
| 152 JNIEnv* env, |
| 153 const base::android::JavaParamRef<jobject>& jobject, |
| 154 jint sdkDisplayId) { |
| 155 displays_.erase(sdkDisplayId); |
| 156 } |
| 157 |
| 158 void DisplayAndroidManager::SetPrimaryDisplayId( |
| 159 JNIEnv* env, |
| 160 const base::android::JavaParamRef<jobject>& jobject, |
| 161 jint sdkDisplayId) { |
| 162 primary_display_id_ = sdkDisplayId; |
| 163 } |
| 164 |
| 165 } // namespace ui |
OLD | NEW |