summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 23:33:48 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-27 23:33:48 +0000
commit3f6ffb8f5a4a78d63a53526c220e74a500fa8eba (patch)
treed07b13f007134878d268db46087f80c19dd8c088 /ui/aura
parent084d97a144cba94376a578190839aa96ddb7d78c (diff)
downloadchromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.zip
chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.gz
chromium_src-3f6ffb8f5a4a78d63a53526c220e74a500fa8eba.tar.bz2
This change makes Aura/Views to use DIP, while keeping layer to use Pixels. This allow chrome/ash to run on high density screen in High Density Incompatible mode (everything scaled to 2x), except for web contents.
I put this behind ENABLE_DIP to avoid regression. I'll make it runtime flag next week when we get render working. BUG=114666 TEST=manual: run with --aura-host-window-size=1000x800*2. Review URL: https://chromiumcodereview.appspot.com/10081011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/aura.gyp2
-rw-r--r--ui/aura/dip_util.cc84
-rw-r--r--ui/aura/dip_util.h41
-rw-r--r--ui/aura/monitor_manager.cc4
-rw-r--r--ui/aura/root_window.cc59
-rw-r--r--ui/aura/root_window.h7
-rw-r--r--ui/aura/single_monitor_manager.cc5
-rw-r--r--ui/aura/window.cc47
-rw-r--r--ui/aura/window.h6
9 files changed, 218 insertions, 37 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 79661ba..f168d06 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -63,6 +63,8 @@
'desktop/desktop_screen_x11.cc',
'desktop/desktop_stacking_client.cc',
'desktop/desktop_stacking_client.h',
+ 'dip_util.cc',
+ 'dip_util.h',
'dispatcher_linux.cc',
'dispatcher_linux.h',
'dispatcher_win.cc',
diff --git a/ui/aura/dip_util.cc b/ui/aura/dip_util.cc
new file mode 100644
index 0000000..c17e0ed
--- /dev/null
+++ b/ui/aura/dip_util.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 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/aura/dip_util.h"
+
+#include "ui/aura/env.h"
+#include "ui/aura/window.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/rect.h"
+
+#if defined(ENABLE_DIP)
+#include "ui/aura/monitor_manager.h"
+#include "ui/gfx/monitor.h"
+#endif
+
+namespace aura {
+#if defined(ENABLE_DIP)
+float GetMonitorScaleFactor(const Window* window) {
+ gfx::Monitor monitor = aura::Env::GetInstance()->monitor_manager()->
+ GetMonitorNearestWindow(window);
+ return monitor.device_scale_factor();
+} // namespace
+#endif
+
+gfx::Point ConvertPointToDIP(const Window* window,
+ const gfx::Point& point_in_pixel) {
+#if defined(ENABLE_DIP)
+ return point_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
+#else
+ return point_in_pixel;
+#endif
+}
+
+gfx::Size ConvertSizeToDIP(const Window* window,
+ const gfx::Size& size_in_pixel) {
+#if defined(ENABLE_DIP)
+ return size_in_pixel.Scale(1.0f / GetMonitorScaleFactor(window));
+#else
+ return size_in_pixel;
+#endif
+}
+
+gfx::Rect ConvertRectToDIP(const Window* window,
+ const gfx::Rect& rect_in_pixel) {
+#if defined(ENABLE_DIP)
+ float scale = 1.0f / GetMonitorScaleFactor(window);
+ return gfx::Rect(rect_in_pixel.origin().Scale(scale),
+ rect_in_pixel.size().Scale(scale));
+#else
+ return rect_in_pixel;
+#endif
+}
+
+gfx::Point ConvertPointToPixel(const Window* window,
+ const gfx::Point& point_in_dip) {
+#if defined(ENABLE_DIP)
+ return point_in_dip.Scale(GetMonitorScaleFactor(window));
+#else
+ return point_in_dip;
+#endif
+}
+
+gfx::Size ConvertSizeToPixel(const Window* window,
+ const gfx::Size& size_in_dip) {
+#if defined(ENABLE_DIP)
+ return size_in_dip.Scale(GetMonitorScaleFactor(window));
+#else
+ return size_in_dip;
+#endif
+}
+
+gfx::Rect ConvertRectToPixel(const Window* window,
+ const gfx::Rect& rect_in_dip) {
+#if defined(ENABLE_DIP)
+ float scale = GetMonitorScaleFactor(window);
+ return gfx::Rect(rect_in_dip.origin().Scale(scale),
+ rect_in_dip.size().Scale(scale));
+#else
+ return rect_in_dip;
+#endif
+}
+} // namespace aura
diff --git a/ui/aura/dip_util.h b/ui/aura/dip_util.h
new file mode 100644
index 0000000..4a5bfef
--- /dev/null
+++ b/ui/aura/dip_util.h
@@ -0,0 +1,41 @@
+// Copyright (c) 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.
+
+#ifndef UI_AURA_DIP_UTIL_H_
+#define UI_AURA_DIP_UTIL_H_
+#pragma once
+
+#include "ui/aura/aura_export.h"
+
+namespace gfx {
+class Point;
+class Size;
+class Rect;
+} // namespace gfx
+
+namespace aura {
+class Window;
+
+#if defined(ENABLE_DIP)
+AURA_EXPORT float GetMonitorScaleFactor(const Window* window);
+#endif
+
+// Utility functions that convert point/size/rect between
+// DIP and pixel coordinates system.
+AURA_EXPORT gfx::Point ConvertPointToDIP(const Window* window,
+ const gfx::Point& point_in_pixel);
+AURA_EXPORT gfx::Size ConvertSizeToDIP(const Window* window,
+ const gfx::Size& size_in_pixel);
+AURA_EXPORT gfx::Rect ConvertRectToDIP(const Window* window,
+ const gfx::Rect& rect_in_pixel);
+AURA_EXPORT gfx::Point ConvertPointToPixel(const Window* window,
+ const gfx::Point& point_in_dip);
+AURA_EXPORT gfx::Size ConvertSizeToPixel(const Window* window,
+ const gfx::Size& size_in_dip);
+AURA_EXPORT gfx::Rect ConvertRectToPixel(const Window* window,
+ const gfx::Rect& rect_in_dip);
+
+} // namespace aura
+
+#endif // UI_AURA_DIP_UTIL_H_
diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc
index 8cf70bc..00535ce 100644
--- a/ui/aura/monitor_manager.cc
+++ b/ui/aura/monitor_manager.cc
@@ -41,8 +41,8 @@ gfx::Monitor MonitorManager::CreateMonitorFromSpec(const std::string& spec) {
} else if (use_fullscreen_host_window_) {
bounds = gfx::Rect(aura::RootWindowHost::GetNativeScreenSize());
}
- gfx::Monitor monitor(synthesized_monitor_id++, bounds);
- monitor.set_device_scale_factor(scale);
+ gfx::Monitor monitor(synthesized_monitor_id++);
+ monitor.SetScaleAndBounds(scale, bounds);
DVLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale;
return monitor;
}
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 37cdb53..aeb3651 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -107,8 +107,6 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds)
draw_on_compositor_unlock_(false),
draw_trace_count_(0) {
SetName("RootWindow");
- last_mouse_location_ = host_->QueryMouseLocation();
-
should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAuraDisableHoldMouseMoves);
@@ -116,7 +114,6 @@ RootWindow::RootWindow(const gfx::Rect& initial_bounds)
host_->GetBounds().size()));
DCHECK(compositor_.get());
compositor_->AddObserver(this);
- Init();
}
RootWindow::~RootWindow() {
@@ -138,6 +135,15 @@ RootWindow::~RootWindow() {
layer()->GetAnimator()->RemoveObserver(this);
}
+void RootWindow::Init() {
+ Window::Init(ui::LAYER_NOT_DRAWN);
+ last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
+ SetBounds(ConvertRectToDIP(this, gfx::Rect(host_->GetBounds().size())));
+ Show();
+ compositor()->SetRootLayer(layer());
+ host_->SetRootWindow(this);
+}
+
void RootWindow::ShowRootWindow() {
host_->Show();
}
@@ -148,7 +154,7 @@ void RootWindow::SetHostSize(const gfx::Size& size) {
bounds.set_size(size);
host_->SetBounds(bounds);
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ = host_->QueryMouseLocation();
+ last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
synthesize_mouse_move_ = false;
}
@@ -160,7 +166,7 @@ void RootWindow::SetHostBounds(const gfx::Rect& bounds) {
DispatchHeldMouseMove();
host_->SetBounds(bounds);
// Requery the location to constrain it within the new root window size.
- last_mouse_location_ = host_->QueryMouseLocation();
+ last_mouse_location_ = ConvertPointToDIP(this, host_->QueryMouseLocation());
synthesize_mouse_move_ = false;
}
@@ -180,8 +186,8 @@ void RootWindow::ShowCursor(bool show) {
host_->ShowCursor(show);
}
-void RootWindow::MoveCursorTo(const gfx::Point& location) {
- host_->MoveCursorTo(location);
+void RootWindow::MoveCursorTo(const gfx::Point& location_in_dip) {
+ host_->MoveCursorTo(ConvertPointToPixel(this, location_in_dip));
}
bool RootWindow::ConfineCursorToWindow() {
@@ -243,7 +249,15 @@ bool RootWindow::DispatchKeyEvent(KeyEvent* event) {
bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
DispatchHeldMouseMove();
+#if defined(ENABLE_DIP)
+ float scale = GetMonitorScaleFactor(this);
+ ui::Transform transform;
+ transform.SetScale(scale, scale);
+ transform.ConcatTransform(layer()->transform());
+ event->UpdateForRootTransform(transform);
+#else
event->UpdateForRootTransform(layer()->transform());
+#endif
last_mouse_location_ = event->location();
synthesize_mouse_move_ = false;
@@ -267,7 +281,15 @@ bool RootWindow::DispatchScrollEvent(ScrollEvent* event) {
bool RootWindow::DispatchTouchEvent(TouchEvent* event) {
DispatchHeldMouseMove();
+#if defined(ENABLE_DIP)
+ float scale = GetMonitorScaleFactor(this);
+ ui::Transform transform;
+ transform.SetScale(scale, scale);
+ transform.ConcatTransform(layer()->transform());
+ event->UpdateForRootTransform(transform);
+#else
event->UpdateForRootTransform(layer()->transform());
+#endif
bool handled = false;
GestureConsumer* consumer = gesture_recognizer_->GetTouchLockedTarget(event);
@@ -342,10 +364,10 @@ void RootWindow::OnHostResized(const gfx::Size& size) {
DispatchHeldMouseMove();
// The compositor should have the same size as the native root window host.
compositor_->WidgetSizeChanged(size);
- gfx::Size old = bounds().size();
+ gfx::Size old(ConvertSizeToDIP(this, bounds().size()));
// The layer, and all the observers should be notified of the
// transformed size of the root window.
- gfx::Rect bounds(size);
+ gfx::Rect bounds(ConvertSizeToDIP(this, size));
layer()->transform().TransformRect(&bounds);
SetBounds(gfx::Rect(bounds.size()));
FOR_EACH_OBSERVER(RootWindowObserver, observers_,
@@ -867,21 +889,20 @@ bool RootWindow::IsFocusedWindow(const Window* window) const {
return focused_window_ == window;
}
-void RootWindow::Init() {
- Window::Init(ui::LAYER_NOT_DRAWN);
- SetBounds(gfx::Rect(host_->GetBounds().size()));
- Show();
- compositor()->SetRootLayer(layer());
- host_->SetRootWindow(this);
-}
-
bool RootWindow::DispatchMouseEventImpl(MouseEvent* event) {
static const int kMouseButtonFlagMask =
ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON;
-
+#if defined(ENABLE_DIP)
+ float scale = GetMonitorScaleFactor(this);
+ ui::Transform transform;
+ transform.SetScale(scale, scale);
+ transform.ConcatTransform(layer()->transform());
+ event->UpdateForRootTransform(transform);
+#else
event->UpdateForRootTransform(layer()->transform());
+#endif
last_mouse_location_ = event->location();
synthesize_mouse_move_ = false;
@@ -948,7 +969,9 @@ void RootWindow::SynthesizeMouseMoveEvent() {
#if !defined(OS_WIN)
// Temporarily disabled for windows. See crbug.com/112222.
gfx::Point orig_mouse_location = last_mouse_location_;
+ orig_mouse_location = ConvertPointToPixel(this, orig_mouse_location);
layer()->transform().TransformPoint(orig_mouse_location);
+ orig_mouse_location = ConvertPointToDIP(this,orig_mouse_location);
// TODO(derat|oshima): Don't use mouse_button_flags_ as it's
// currently broken. See/ crbug.com/107931.
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 500f052..94ec02f 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "ui/aura/aura_export.h"
+#include "ui/aura/dip_util.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/window.h"
#include "ui/base/cursor/cursor.h"
@@ -97,6 +98,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
Window* capture_window() { return capture_window_; }
Window* focused_window() { return focused_window_; }
+ // Initializes the root window.
+ void Init();
+
// Shows the root window host.
void ShowRootWindow();
@@ -320,9 +324,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
virtual Window* GetFocusedWindow() OVERRIDE;
virtual bool IsFocusedWindow(const Window* window) const OVERRIDE;
- // Initializes the root window.
- void Init();
-
// We hold and aggregate mouse drags as a way of throttling resizes when
// HoldMouseMoves() is called. The following methods are used to dispatch held
// and newly incoming mouse events, typically when an event other than a mouse
diff --git a/ui/aura/single_monitor_manager.cc b/ui/aura/single_monitor_manager.cc
index aaeae07..9df0b71 100644
--- a/ui/aura/single_monitor_manager.cc
+++ b/ui/aura/single_monitor_manager.cc
@@ -39,7 +39,7 @@ void SingleMonitorManager::OnNativeMonitorsChanged(
const std::vector<gfx::Monitor>& monitors) {
DCHECK(monitors.size() > 0);
if (use_fullscreen_host_window()) {
- monitor_.SetSizeAndUpdateWorkArea(monitors[0].bounds().size());
+ monitor_.SetSize(monitors[0].bounds().size());
NotifyBoundsChanged(monitor_);
}
}
@@ -50,6 +50,7 @@ RootWindow* SingleMonitorManager::CreateRootWindowForMonitor(
DCHECK_EQ(monitor_.id(), monitor.id());
root_window_ = new RootWindow(monitor.bounds());
root_window_->AddObserver(this);
+ root_window_->Init();
return root_window_;
}
@@ -91,7 +92,7 @@ void SingleMonitorManager::Init() {
}
void SingleMonitorManager::Update(const gfx::Size size) {
- monitor_.SetSizeAndUpdateWorkArea(size);
+ monitor_.SetSize(size);
}
} // namespace aura
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 8788d0a..28c8b80 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -12,6 +12,7 @@
#include "ui/aura/client/event_client.h"
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/client/visibility_client.h"
+#include "ui/aura/dip_util.h"
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
@@ -210,6 +211,10 @@ gfx::Rect Window::GetBoundsInRootWindow() const {
return gfx::Rect(origin, bounds().size());
}
+const gfx::Rect& Window::GetBoundsInPixel() const {
+ return layer_->bounds();
+}
+
void Window::SetTransform(const ui::Transform& transform) {
RootWindow* root_window = GetRootWindow();
bool contained_mouse = IsVisible() && root_window &&
@@ -241,23 +246,28 @@ void Window::SetBounds(const gfx::Rect& new_bounds) {
}
gfx::Rect Window::GetTargetBounds() const {
- return layer_->GetTargetBounds();
+ return ConvertRectToDIP(this, layer_->GetTargetBounds());
}
-const gfx::Rect& Window::bounds() const {
+gfx::Rect Window::bounds() const {
+#if defined(ENABLE_DIP)
+ return ConvertRectToDIP(this, layer_->bounds());
+#else
return layer_->bounds();
+#endif
}
-void Window::SchedulePaintInRect(const gfx::Rect& rect) {
+void Window::SchedulePaintInRect(const gfx::Rect& rect_in_dip) {
+ gfx::Rect rect = ConvertRectToPixel(this, rect_in_dip);
if (layer_->SchedulePaint(rect)) {
FOR_EACH_OBSERVER(
- WindowObserver, observers_, OnWindowPaintScheduled(this, rect));
+ WindowObserver, observers_, OnWindowPaintScheduled(this, rect_in_dip));
}
}
void Window::SetExternalTexture(ui::Texture* texture) {
layer_->SetExternalTexture(texture);
- gfx::Rect region(gfx::Point(), bounds().size());
+ gfx::Rect region(bounds().size());
FOR_EACH_OBSERVER(
WindowObserver, observers_, OnWindowPaintScheduled(this, region));
}
@@ -373,7 +383,14 @@ void Window::ConvertPointToWindow(const Window* source,
gfx::Point* point) {
if (!source)
return;
+ // TODO(oshima): We probably need to handle source's root != target's root
+ // case under multi monitor environment.
+ *point = ConvertPointToPixel(source, *point);
ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
+ if (target)
+ *point = ConvertPointToDIP(target, *point);
+ else
+ *point = ConvertPointToDIP(source, *point);
}
gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
@@ -525,6 +542,9 @@ void* Window::GetNativeWindowProperty(const char* key) const {
return reinterpret_cast<void*>(GetPropertyInternal(key, 0));
}
+///////////////////////////////////////////////////////////////////////////////
+// Window, private:
+
intptr_t Window::SetPropertyInternal(const void* key,
const char* name,
PropertyDeallocator deallocator,
@@ -553,9 +573,6 @@ intptr_t Window::GetPropertyInternal(const void* key,
return iter->second.value;
}
-///////////////////////////////////////////////////////////////////////////////
-// Window, private:
-
void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
gfx::Rect actual_new_bounds(new_bounds);
@@ -573,11 +590,11 @@ void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
IsVisible() &&
root_window && ContainsPointInRoot(root_window->last_mouse_location());
- const gfx::Rect old_bounds = layer_->GetTargetBounds();
+ const gfx::Rect old_bounds = GetTargetBounds();
// Always need to set the layer's bounds -- even if it is to the same thing.
// This may cause important side effects such as stopping animation.
- layer_->SetBounds(actual_new_bounds);
+ layer_->SetBounds(ConvertRectToPixel(this, actual_new_bounds));
// If we're not changing the effective bounds, then we can bail early and skip
// notifying our listeners.
@@ -791,8 +808,16 @@ void Window::NotifyAddedToRootWindow() {
}
void Window::OnPaintLayer(gfx::Canvas* canvas) {
- if (delegate_)
+ if (delegate_) {
+#if defined(ENABLE_DIP)
+ float scale = GetMonitorScaleFactor(this);
+ canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale));
+#endif
delegate_->OnPaint(canvas);
+#if defined(ENABLE_DIP)
+ canvas->Restore();
+#endif
+ }
}
void Window::UpdateLayerName(const std::string& name) {
diff --git a/ui/aura/window.h b/ui/aura/window.h
index eca2aac..6ba4c28 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -112,7 +112,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
WindowDelegate* delegate() { return delegate_; }
- const gfx::Rect& bounds() const;
+ // TODO(oshima): Rename this to GetBounds().
+ gfx::Rect bounds() const;
Window* parent() { return parent_; }
const Window* parent() const { return parent_; }
@@ -143,6 +144,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
// support.
gfx::Rect GetBoundsInRootWindow() const;
+ // Returns the bounds in pixel coordinates.
+ const gfx::Rect& GetBoundsInPixel() const;
+
virtual void SetTransform(const ui::Transform& transform);
// Assigns a LayoutManager to size and place child windows.