OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/aura/client/activation_client.h" | 10 #include "ui/aura/client/activation_client.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "ui/views/widget/tooltip_manager_aura.h" | 33 #include "ui/views/widget/tooltip_manager_aura.h" |
34 #include "ui/views/widget/widget_delegate.h" | 34 #include "ui/views/widget/widget_delegate.h" |
35 | 35 |
36 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
37 #include "base/win/scoped_gdi_object.h" | 37 #include "base/win/scoped_gdi_object.h" |
38 #include "base/win/win_util.h" | 38 #include "base/win/win_util.h" |
39 #include "ui/base/l10n/l10n_util_win.h" | 39 #include "ui/base/l10n/l10n_util_win.h" |
40 #endif | 40 #endif |
41 | 41 |
42 #if defined(ENABLE_DIP) | 42 #if defined(ENABLE_DIP) |
43 #include "ui/aura/monitor.h" | 43 #include "ui/gfx/monitor.h" |
44 #include "ui/aura/monitor_manager.h" | |
45 #endif | 44 #endif |
46 | 45 |
47 namespace views { | 46 namespace views { |
48 | 47 |
49 namespace { | 48 namespace { |
50 | 49 |
51 aura::client::WindowType GetAuraWindowTypeForWidgetType( | 50 aura::client::WindowType GetAuraWindowTypeForWidgetType( |
52 Widget::InitParams::Type type) { | 51 Widget::InitParams::Type type) { |
53 switch (type) { | 52 switch (type) { |
54 case Widget::InitParams::TYPE_WINDOW: | 53 case Widget::InitParams::TYPE_WINDOW: |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 InputMethod* input_method = new InputMethodBridge(this, host); | 345 InputMethod* input_method = new InputMethodBridge(this, host); |
347 input_method->Init(GetWidget()); | 346 input_method->Init(GetWidget()); |
348 return input_method; | 347 return input_method; |
349 } | 348 } |
350 | 349 |
351 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | 350 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { |
352 gfx::Rect parent_bounds(window_->parent()->GetScreenBounds()); | 351 gfx::Rect parent_bounds(window_->parent()->GetScreenBounds()); |
353 // When centering window, we take the intersection of the host and | 352 // When centering window, we take the intersection of the host and |
354 // the parent. We assume the root window represents the visible | 353 // the parent. We assume the root window represents the visible |
355 // rect of a single screen. | 354 // rect of a single screen. |
356 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(window_); | 355 gfx::Rect work_area = |
| 356 gfx::Screen::GetMonitorNearestWindow(window_).work_area(); |
357 parent_bounds = parent_bounds.Intersect(work_area); | 357 parent_bounds = parent_bounds.Intersect(work_area); |
358 | 358 |
359 // If |window_|'s transient parent's bounds are big enough to fit it, then we | 359 // If |window_|'s transient parent's bounds are big enough to fit it, then we |
360 // center it with respect to the transient parent. | 360 // center it with respect to the transient parent. |
361 if (window_->transient_parent()) { | 361 if (window_->transient_parent()) { |
362 gfx::Rect transient_parent_rect = window_->transient_parent()-> | 362 gfx::Rect transient_parent_rect = window_->transient_parent()-> |
363 GetScreenBounds().Intersect(work_area); | 363 GetScreenBounds().Intersect(work_area); |
364 if (transient_parent_rect.height() >= size.height() && | 364 if (transient_parent_rect.height() >= size.height() && |
365 transient_parent_rect.width() >= size.width()) | 365 transient_parent_rect.width() >= size.width()) |
366 parent_bounds = transient_parent_rect; | 366 parent_bounds = transient_parent_rect; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 if (window_ && window_->GetFocusManager() && | 659 if (window_ && window_->GetFocusManager() && |
660 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) | 660 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) |
661 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); | 661 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); |
662 } | 662 } |
663 | 663 |
664 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { | 664 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { |
665 window_->GetFocusManager()->SetFocusedWindow(native_view, NULL); | 665 window_->GetFocusManager()->SetFocusedWindow(native_view, NULL); |
666 } | 666 } |
667 | 667 |
668 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 668 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
669 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); | 669 return gfx::Screen::GetMonitorNearestWindow(GetNativeView()).work_area(); |
670 } | 670 } |
671 | 671 |
672 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | 672 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { |
673 if (!value) | 673 if (!value) |
674 active_window_observer_.reset(); | 674 active_window_observer_.reset(); |
675 else | 675 else |
676 active_window_observer_.reset(new ActiveWindowObserver(this)); | 676 active_window_observer_.reset(new ActiveWindowObserver(this)); |
677 } | 677 } |
678 | 678 |
679 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { | 679 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 bool NativeWidgetAura::CanFocus() { | 816 bool NativeWidgetAura::CanFocus() { |
817 return can_activate_; | 817 return can_activate_; |
818 } | 818 } |
819 | 819 |
820 void NativeWidgetAura::OnCaptureLost() { | 820 void NativeWidgetAura::OnCaptureLost() { |
821 delegate_->OnMouseCaptureLost(); | 821 delegate_->OnMouseCaptureLost(); |
822 } | 822 } |
823 | 823 |
824 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 824 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { |
825 #if defined(ENABLE_DIP) | 825 #if defined(ENABLE_DIP) |
826 aura::Monitor* monitor = GetMonitor(); | |
827 canvas->Save(); | 826 canvas->Save(); |
828 float scale = monitor->GetDeviceScaleFactor(); | 827 float scale = GetMonitorScaleFactor(); |
829 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); | 828 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); |
830 #endif | 829 #endif |
831 delegate_->OnNativeWidgetPaint(canvas); | 830 delegate_->OnNativeWidgetPaint(canvas); |
832 #if defined(ENABLE_DIP) | 831 #if defined(ENABLE_DIP) |
833 canvas->Restore(); | 832 canvas->Restore(); |
834 #endif | 833 #endif |
835 } | 834 } |
836 | 835 |
837 void NativeWidgetAura::OnWindowDestroying() { | 836 void NativeWidgetAura::OnWindowDestroying() { |
838 delegate_->OnNativeWidgetDestroying(); | 837 delegate_->OnNativeWidgetDestroying(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 //////////////////////////////////////////////////////////////////////////////// | 905 //////////////////////////////////////////////////////////////////////////////// |
907 // NativeWidgetAura, private: | 906 // NativeWidgetAura, private: |
908 | 907 |
909 void NativeWidgetAura::SetInitialFocus() { | 908 void NativeWidgetAura::SetInitialFocus() { |
910 // The window does not get keyboard messages unless we focus it. | 909 // The window does not get keyboard messages unless we focus it. |
911 if (!GetWidget()->SetInitialFocus()) | 910 if (!GetWidget()->SetInitialFocus()) |
912 window_->Focus(); | 911 window_->Focus(); |
913 } | 912 } |
914 | 913 |
915 #if defined(ENABLE_DIP) | 914 #if defined(ENABLE_DIP) |
916 aura::Monitor* NativeWidgetAura::GetMonitor() const { | 915 float NativeWidgetAura::GetMonitorScaleFactor() const { |
917 return aura::Env::GetInstance()->monitor_manager()-> | 916 return gfx::Screen::GetMonitorNearestWindow(window_).device_scale_factor(); |
918 GetMonitorNearestWindow(window_); | |
919 } | 917 } |
920 | 918 |
921 gfx::Point NativeWidgetAura::ConvertPointFromMonitor( | 919 gfx::Point NativeWidgetAura::ConvertPointFromMonitor( |
922 const gfx::Point& point) const { | 920 const gfx::Point& point) const { |
923 return point.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); | 921 return point.Scale(1.0f / GetMonitorScaleFactor()); |
924 } | 922 } |
925 | 923 |
926 gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( | 924 gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( |
927 const gfx::Size& size) const { | 925 const gfx::Size& size) const { |
928 return size.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); | 926 return size.Scale(1.0f / GetMonitorScaleFactor()); |
929 } | 927 } |
930 | 928 |
931 gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( | 929 gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( |
932 const gfx::Rect& rect) const { | 930 const gfx::Rect& rect) const { |
933 float scale = 1.0f / GetMonitor()->GetDeviceScaleFactor(); | 931 float scale = 1.0f / GetMonitorScaleFactor(); |
934 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); | 932 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); |
935 } | 933 } |
936 | 934 |
937 gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { | 935 gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { |
938 return size.Scale(GetMonitor()->GetDeviceScaleFactor()); | 936 return size.Scale(GetMonitorScaleFactor()); |
939 } | 937 } |
940 | 938 |
941 gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { | 939 gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { |
942 float scale = GetMonitor()->GetDeviceScaleFactor(); | 940 float scale = GetMonitorScaleFactor(); |
943 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); | 941 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); |
944 } | 942 } |
945 #endif | 943 #endif |
946 | 944 |
947 //////////////////////////////////////////////////////////////////////////////// | 945 //////////////////////////////////////////////////////////////////////////////// |
948 // Widget, public: | 946 // Widget, public: |
949 | 947 |
950 // static | 948 // static |
951 void Widget::NotifyLocaleChanged() { | 949 void Widget::NotifyLocaleChanged() { |
952 // Deliberately not implemented. | 950 // Deliberately not implemented. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 } | 1047 } |
1050 } | 1048 } |
1051 | 1049 |
1052 // static | 1050 // static |
1053 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1051 bool NativeWidgetPrivate::IsMouseButtonDown() { |
1054 return aura::Env::GetInstance()->is_mouse_button_down(); | 1052 return aura::Env::GetInstance()->is_mouse_button_down(); |
1055 } | 1053 } |
1056 | 1054 |
1057 } // namespace internal | 1055 } // namespace internal |
1058 } // namespace views | 1056 } // namespace views |
OLD | NEW |