diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 17:05:23 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 17:05:23 +0000 |
commit | 25bc29d411ee9b75c133c007f5c18710ffa589ca (patch) | |
tree | 626a219a163fbe8e5afea372343dbcaccdfb1e51 /ui | |
parent | 83a072aa7f45bd4fc5c4ecbfa0fd565b3fe5f648 (diff) | |
download | chromium_src-25bc29d411ee9b75c133c007f5c18710ffa589ca.zip chromium_src-25bc29d411ee9b75c133c007f5c18710ffa589ca.tar.gz chromium_src-25bc29d411ee9b75c133c007f5c18710ffa589ca.tar.bz2 |
- Add temporary support for High Density Incompatible mode (scale to 2x) to NativeWidgetAura.
This allow us to work on making views HD compatible while I'm working on aura side.
Conversion code will be removed once Aura supports scaling factor.
- Add scaleing method to point/size
- Add set_device_scale_factor that I missed.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10068005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/monitor.h | 11 | ||||
-rw-r--r-- | ui/aura/monitor_manager.cc | 1 | ||||
-rw-r--r-- | ui/gfx/point_base.h | 9 | ||||
-rw-r--r-- | ui/gfx/size_base.h | 9 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 96 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.h | 14 |
6 files changed, 137 insertions, 3 deletions
diff --git a/ui/aura/monitor.h b/ui/aura/monitor.h index 496263e..f62a781 100644 --- a/ui/aura/monitor.h +++ b/ui/aura/monitor.h @@ -13,6 +13,13 @@ namespace aura { +// Note: The screen and monitor currently uses pixels coordinate +// system. ENABLE_DIP macro (which is enabled with enable_dip=1 gyp +// flag) will make this inconsistent with views' coordinate system +// because views will use DIP coordinate system, which uses +// (1.0/device_scale_factor) scale of the pixel coordinate system. +// TODO(oshima): Change aura/screen to DIP coordinate system and +// update this comment. class AURA_EXPORT Monitor { public: Monitor(); @@ -42,6 +49,10 @@ class AURA_EXPORT Monitor { return device_scale_factor_; } + void set_device_scale_factor(float scale) { + device_scale_factor_ = scale; + } + // Returns the monitor's work area. gfx::Rect GetWorkAreaBounds() const; diff --git a/ui/aura/monitor_manager.cc b/ui/aura/monitor_manager.cc index de23f58..b3f18b9 100644 --- a/ui/aura/monitor_manager.cc +++ b/ui/aura/monitor_manager.cc @@ -41,6 +41,7 @@ Monitor* MonitorManager::CreateMonitorFromSpec(const std::string& spec) { } Monitor* monitor = new Monitor(); monitor->set_bounds(bounds); + monitor->set_device_scale_factor(scale); VLOG(1) << "Monitor bounds=" << bounds.ToString() << ", scale=" << scale; return monitor; } diff --git a/ui/gfx/point_base.h b/ui/gfx/point_base.h index 8fb8766..1568c52 100644 --- a/ui/gfx/point_base.h +++ b/ui/gfx/point_base.h @@ -33,6 +33,15 @@ class UI_EXPORT PointBase { y_ += delta_y; } + Class Scale(float scale) const { + return Scale(scale, scale); + } + + Class Scale(float x_scale, float y_scale) const { + return Class(static_cast<Type>(x_ * x_scale), + static_cast<Type>(y_ * y_scale)); + } + Class Add(const Class& other) const{ const Class* orig = static_cast<const Class*>(this); Class copy = *orig; diff --git a/ui/gfx/size_base.h b/ui/gfx/size_base.h index 1256f7f..590989e 100644 --- a/ui/gfx/size_base.h +++ b/ui/gfx/size_base.h @@ -32,6 +32,15 @@ class UI_EXPORT SizeBase { set_height(height_ + height); } + Class Scale(float scale) const { + return Scale(scale, scale); + } + + Class Scale(float x_scale, float y_scale) const { + return Class(static_cast<Type>(width_ * x_scale), + static_cast<Type>(height_ * y_scale)); + } + void set_width(Type width); void set_height(Type height); diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index db69d23..9de1e78 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -41,6 +41,11 @@ #include "ui/base/l10n/l10n_util_win.h" #endif +#if defined(ENABLE_DIP) +#include "ui/aura/monitor.h" +#include "ui/aura/monitor_manager.h" +#endif + namespace views { bool NativeWidgetAura::g_aura_desktop_hax = false; @@ -430,13 +435,21 @@ void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { } gfx::Rect NativeWidgetAura::GetWindowScreenBounds() const { +#if defined(ENABLE_DIP) + return ConvertRectFromMonitor(window_->GetScreenBounds()); +#else return window_->GetScreenBounds(); +#endif } gfx::Rect NativeWidgetAura::GetClientAreaScreenBounds() const { // View-to-screen coordinate system transformations depend on this returning // the full window bounds, for example View::ConvertPointToScreen(). +#if defined(ENABLE_DIP) + return ConvertRectFromMonitor(window_->GetScreenBounds()); +#else return window_->GetScreenBounds(); +#endif } gfx::Rect NativeWidgetAura::GetRestoredBounds() const { @@ -447,7 +460,12 @@ gfx::Rect NativeWidgetAura::GetRestoredBounds() const { return window_->bounds(); gfx::Rect* restore_bounds = window_->GetProperty(aura::client::kRestoreBoundsKey); +#if defined(ENABLE_DIP) + return ConvertRectFromMonitor( + restore_bounds ? *restore_bounds : window_->bounds()); +#else return restore_bounds ? *restore_bounds : window_->bounds(); +#endif } void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { @@ -458,12 +476,19 @@ void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { bounds.set_x(0); bounds.set_y(0); } - +#if defined(ENABLE_DIP) + bounds = ConvertRectToMonitor(bounds); +#endif window_->SetBounds(bounds); } void NativeWidgetAura::SetSize(const gfx::Size& size) { +#if defined(ENABLE_DIP) + gfx::Size monitor_size = ConvertSizeToMonitor(size); + window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); +#else window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); +#endif } void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { @@ -519,7 +544,11 @@ void NativeWidgetAura::Hide() { void NativeWidgetAura::ShowMaximizedWithBounds( const gfx::Rect& restored_bounds) { +#if defined(ENABLE_DIP) + SetRestoreBounds(window_, ConvertRectToMonitor(restored_bounds)); +#else SetRestoreBounds(window_, restored_bounds); +#endif ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); } @@ -631,8 +660,13 @@ void NativeWidgetAura::RunShellDrag(View* view, } void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { - if (window_) + if (window_) { +#if defined(ENABLE_DIP) + window_->SchedulePaintInRect(ConvertRectToMonitor(rect)); +#else window_->SchedulePaintInRect(rect); +#endif + } } void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { @@ -705,8 +739,14 @@ void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { if (old_bounds.origin() != new_bounds.origin()) GetWidget()->widget_delegate()->OnWidgetMove(); - if (old_bounds.size() != new_bounds.size()) + if (old_bounds.size() != new_bounds.size()) { +#if defined(ENABLE_DIP) + delegate_->OnNativeWidgetSizeChanged( + ConvertSizeFromMonitor(new_bounds.size())); +#else delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); +#endif + } } void NativeWidgetAura::OnFocus() { @@ -765,7 +805,16 @@ bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) { MouseWheelEvent wheel_event(scroll_event); return delegate_->OnMouseEvent(wheel_event); } +#if defined(ENABLE_DIP) + aura::MouseEvent translated_event( + event->type(), + ConvertPointFromMonitor(event->location()), + ConvertPointFromMonitor(event->root_location()), + event->flags()); + MouseEvent mouse_event(&translated_event); +#else MouseEvent mouse_event(event); +#endif if (tooltip_manager_.get()) tooltip_manager_->UpdateTooltip(); return delegate_->OnMouseEvent(mouse_event); @@ -792,7 +841,16 @@ void NativeWidgetAura::OnCaptureLost() { } void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { +#if defined(ENABLE_DIP) + aura::Monitor* monitor = GetMonitor(); + canvas->Save(); + float scale = monitor->GetDeviceScaleFactor(); + canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); +#endif delegate_->OnNativeWidgetPaint(canvas); +#if defined(ENABLE_DIP) + canvas->Restore(); +#endif } void NativeWidgetAura::OnWindowDestroying() { @@ -890,6 +948,38 @@ void NativeWidgetAura::SetInitialFocus() { window_->Focus(); } +#if defined(ENABLE_DIP) +aura::Monitor* NativeWidgetAura::GetMonitor() const { + return aura::Env::GetInstance()->monitor_manager()-> + GetMonitorNearestWindow(window_); +} + +gfx::Point NativeWidgetAura::ConvertPointFromMonitor( + const gfx::Point& point) const { + return point.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); +} + +gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( + const gfx::Size& size) const { + return size.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); +} + +gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( + const gfx::Rect& rect) const { + float scale = 1.0f / GetMonitor()->GetDeviceScaleFactor(); + return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); +} + +gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { + return size.Scale(GetMonitor()->GetDeviceScaleFactor()); +} + +gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { + float scale = GetMonitor()->GetDeviceScaleFactor(); + return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); +} +#endif + //////////////////////////////////////////////////////////////////////////////// // Widget, public: diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index d9a23ea..d09a77d 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -17,6 +17,7 @@ #include "ui/views/widget/native_widget_private.h" namespace aura { +class Monitor; class RootWindow; class Window; } @@ -175,6 +176,19 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, void SetInitialFocus(); +#if defined(ENABLE_DIP) + // Returns the monitor in which this widget is placed. + aura::Monitor* GetMonitor() const; + + // Utility functions that convert point/size/rect between + // the monitor's coordinate system and the widget's coordinate system. + gfx::Point ConvertPointFromMonitor(const gfx::Point& point) const; + gfx::Size ConvertSizeFromMonitor(const gfx::Size& size) const; + gfx::Rect ConvertRectFromMonitor(const gfx::Rect& rect) const; + gfx::Size ConvertSizeToMonitor(const gfx::Size& size) const; + gfx::Rect ConvertRectToMonitor(const gfx::Rect& rect) const; +#endif + internal::NativeWidgetDelegate* delegate_; scoped_ptr<aura::RootWindow> root_window_; |