| Index: ui/android/display_android_manager.cc
|
| diff --git a/ui/android/display_android_manager.cc b/ui/android/display_android_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..82c040d59f86026d039feb5659c1928554b92c6a
|
| --- /dev/null
|
| +++ b/ui/android/display_android_manager.cc
|
| @@ -0,0 +1,163 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/android/display_android_manager.h"
|
| +
|
| +#include <jni.h>
|
| +#include <map>
|
| +
|
| +#include "base/android/jni_android.h"
|
| +//#include "base/macros.h"
|
| +#include "base/stl_util.h"
|
| +#include "jni/DisplayAndroidManager_jni.h"
|
| +#include "ui/android/screen_android.h"
|
| +#include "ui/android/window_android.h"
|
| +#include "ui/display/display.h"
|
| +
|
| +namespace ui {
|
| +
|
| +using base::android::AttachCurrentThread;
|
| +using display::Display;
|
| +using display::DisplayObserver;
|
| +
|
| +display::Screen* CreateScreenAndroid() {
|
| + // DisplayAndroidManager should be created only once.
|
| + DCHECK(!display::Screen::GetScreen());
|
| +
|
| + DisplayAndroidManager* result = new DisplayAndroidManager();
|
| +
|
| + JNIEnv* env = AttachCurrentThread();
|
| + Java_DisplayAndroidManager_onNativeSideCreated(env, (jlong)result);
|
| + return result;
|
| +}
|
| +
|
| +bool RegisterScreenAndroid(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +DisplayAndroidManager::DisplayAndroidManager() {}
|
| +
|
| +DisplayAndroidManager::~DisplayAndroidManager() {}
|
| +
|
| +// Screen interface.
|
| +
|
| +gfx::Point DisplayAndroidManager::GetCursorScreenPoint() {
|
| + NOTIMPLEMENTED();
|
| + return gfx::Point();
|
| +}
|
| +
|
| +bool DisplayAndroidManager::IsWindowUnderCursor(gfx::NativeWindow window) {
|
| + NOTIMPLEMENTED();
|
| + return false;
|
| +}
|
| +
|
| +gfx::NativeWindow DisplayAndroidManager::GetWindowAtScreenPoint(
|
| + const gfx::Point& point) {
|
| + NOTIMPLEMENTED();
|
| + return NULL;
|
| +}
|
| +
|
| +int DisplayAndroidManager::GetNumDisplays() const {
|
| + DCHECK_GE(displays_.size(), 1U);
|
| + return displays_.size();
|
| +}
|
| +
|
| +std::vector<Display> DisplayAndroidManager::GetAllDisplays() const {
|
| + DCHECK_GE(displays_.size(), 1U);
|
| +
|
| + std::vector<Display> result;
|
| + for (const auto& display : displays_)
|
| + result.push_back(display.second);
|
| +
|
| + return result;
|
| +}
|
| +
|
| +Display DisplayAndroidManager::GetDisplayNearestWindow(
|
| + gfx::NativeView view) const {
|
| + ui::WindowAndroid* window = view ? view->GetWindowAndroid() : nullptr;
|
| + if (window) {
|
| + DisplayMap::const_iterator it = displays_.find(window->display_id());
|
| + if (it != displays_.end()) {
|
| + return it->second;
|
| + }
|
| + }
|
| + return GetPrimaryDisplay();
|
| +}
|
| +
|
| +Display DisplayAndroidManager::GetDisplayNearestPoint(
|
| + const gfx::Point& point) const {
|
| + NOTIMPLEMENTED();
|
| + return GetPrimaryDisplay();
|
| +}
|
| +
|
| +Display DisplayAndroidManager::GetDisplayMatching(
|
| + const gfx::Rect& match_rect) const {
|
| + NOTIMPLEMENTED();
|
| + return GetPrimaryDisplay();
|
| +}
|
| +
|
| +Display DisplayAndroidManager::GetPrimaryDisplay() const {
|
| + DisplayMap::const_iterator it = displays_.find(primary_display_id_);
|
| + // Primary display must be set before the first call to this method.
|
| + CHECK(it != displays_.end());
|
| + return it->second;
|
| +}
|
| +
|
| +void DisplayAndroidManager::AddObserver(DisplayObserver* observer) {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +void DisplayAndroidManager::RemoveObserver(DisplayObserver* observer) {
|
| + NOTIMPLEMENTED();
|
| +}
|
| +
|
| +// Methods called from Java
|
| +
|
| +void DisplayAndroidManager::UpdateDisplay(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& jobject,
|
| + jint sdkDisplayId,
|
| + jint physicalWidth,
|
| + jint physicalHeight,
|
| + jint width,
|
| + jint height,
|
| + jfloat dipScale,
|
| + jint rotationDegrees,
|
| + jint bitsPerPixel,
|
| + jint bitsPerComponent) {
|
| + gfx::Rect bounds_in_pixels = gfx::Rect(physicalWidth, physicalHeight);
|
| +
|
| + // Physical width and height might be not supported.
|
| + if (bounds_in_pixels.IsEmpty())
|
| + bounds_in_pixels = gfx::Rect(width, height);
|
| +
|
| + const gfx::Rect bounds_in_dip = gfx::Rect(
|
| + gfx::ScaleToCeiledSize(bounds_in_pixels.size(), 1.0f / dipScale));
|
| +
|
| + display::Display display(sdkDisplayId, bounds_in_dip);
|
| +
|
| + display.set_device_scale_factor(dipScale);
|
| + display.SetRotationAsDegree(rotationDegrees);
|
| + display.set_color_depth(bitsPerPixel);
|
| + display.set_depth_per_component(bitsPerComponent);
|
| + display.set_is_monochrome(bitsPerComponent == 0);
|
| +
|
| + displays_[sdkDisplayId] = display;
|
| +}
|
| +
|
| +void DisplayAndroidManager::RemoveDisplay(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& jobject,
|
| + jint sdkDisplayId) {
|
| + displays_.erase(sdkDisplayId);
|
| +}
|
| +
|
| +void DisplayAndroidManager::SetPrimaryDisplayId(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& jobject,
|
| + jint sdkDisplayId) {
|
| + primary_display_id_ = sdkDisplayId;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|