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()->GetBoundsInRootWindow()); | 351 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); |
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 GetBoundsInRootWindow().Intersect(work_area); | 363 GetBoundsInRootWindow().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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 if (window_ && window_->GetFocusManager() && | 665 if (window_ && window_->GetFocusManager() && |
666 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) | 666 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) |
667 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); | 667 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); |
668 } | 668 } |
669 | 669 |
670 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { | 670 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { |
671 window_->GetFocusManager()->SetFocusedWindow(native_view, NULL); | 671 window_->GetFocusManager()->SetFocusedWindow(native_view, NULL); |
672 } | 672 } |
673 | 673 |
674 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 674 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
675 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); | 675 return gfx::Screen::GetMonitorNearestWindow(GetNativeView()).work_area(); |
676 } | 676 } |
677 | 677 |
678 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | 678 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { |
679 if (!value) | 679 if (!value) |
680 active_window_observer_.reset(); | 680 active_window_observer_.reset(); |
681 else | 681 else |
682 active_window_observer_.reset(new ActiveWindowObserver(this)); | 682 active_window_observer_.reset(new ActiveWindowObserver(this)); |
683 } | 683 } |
684 | 684 |
685 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { | 685 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 bool NativeWidgetAura::CanFocus() { | 822 bool NativeWidgetAura::CanFocus() { |
823 return can_activate_; | 823 return can_activate_; |
824 } | 824 } |
825 | 825 |
826 void NativeWidgetAura::OnCaptureLost() { | 826 void NativeWidgetAura::OnCaptureLost() { |
827 delegate_->OnMouseCaptureLost(); | 827 delegate_->OnMouseCaptureLost(); |
828 } | 828 } |
829 | 829 |
830 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | 830 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { |
831 #if defined(ENABLE_DIP) | 831 #if defined(ENABLE_DIP) |
832 aura::Monitor* monitor = GetMonitor(); | |
833 canvas->Save(); | 832 canvas->Save(); |
834 float scale = monitor->GetDeviceScaleFactor(); | 833 float scale = GetMonitorScaleFactor(); |
835 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); | 834 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); |
836 #endif | 835 #endif |
837 delegate_->OnNativeWidgetPaint(canvas); | 836 delegate_->OnNativeWidgetPaint(canvas); |
838 #if defined(ENABLE_DIP) | 837 #if defined(ENABLE_DIP) |
839 canvas->Restore(); | 838 canvas->Restore(); |
840 #endif | 839 #endif |
841 } | 840 } |
842 | 841 |
843 void NativeWidgetAura::OnWindowDestroying() { | 842 void NativeWidgetAura::OnWindowDestroying() { |
844 delegate_->OnNativeWidgetDestroying(); | 843 delegate_->OnNativeWidgetDestroying(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 //////////////////////////////////////////////////////////////////////////////// | 911 //////////////////////////////////////////////////////////////////////////////// |
913 // NativeWidgetAura, private: | 912 // NativeWidgetAura, private: |
914 | 913 |
915 void NativeWidgetAura::SetInitialFocus() { | 914 void NativeWidgetAura::SetInitialFocus() { |
916 // The window does not get keyboard messages unless we focus it. | 915 // The window does not get keyboard messages unless we focus it. |
917 if (!GetWidget()->SetInitialFocus()) | 916 if (!GetWidget()->SetInitialFocus()) |
918 window_->Focus(); | 917 window_->Focus(); |
919 } | 918 } |
920 | 919 |
921 #if defined(ENABLE_DIP) | 920 #if defined(ENABLE_DIP) |
922 aura::Monitor* NativeWidgetAura::GetMonitor() const { | 921 float NativeWidgetAura::GetMonitorScaleFactor() const { |
923 return aura::Env::GetInstance()->monitor_manager()-> | 922 return gfx::Screen::GetMonitorNearestWindow(window_).device_scale_factor(); |
924 GetMonitorNearestWindow(window_); | |
925 } | 923 } |
926 | 924 |
927 gfx::Point NativeWidgetAura::ConvertPointFromMonitor( | 925 gfx::Point NativeWidgetAura::ConvertPointFromMonitor( |
928 const gfx::Point& point) const { | 926 const gfx::Point& point) const { |
929 return point.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); | 927 return point.Scale(1.0f / GetMonitorScaleFactor()); |
930 } | 928 } |
931 | 929 |
932 gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( | 930 gfx::Size NativeWidgetAura::ConvertSizeFromMonitor( |
933 const gfx::Size& size) const { | 931 const gfx::Size& size) const { |
934 return size.Scale(1.0f / GetMonitor()->GetDeviceScaleFactor()); | 932 return size.Scale(1.0f / GetMonitorScaleFactor()); |
935 } | 933 } |
936 | 934 |
937 gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( | 935 gfx::Rect NativeWidgetAura::ConvertRectFromMonitor( |
938 const gfx::Rect& rect) const { | 936 const gfx::Rect& rect) const { |
939 float scale = 1.0f / GetMonitor()->GetDeviceScaleFactor(); | 937 float scale = 1.0f / GetMonitorScaleFactor(); |
940 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); | 938 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); |
941 } | 939 } |
942 | 940 |
943 gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { | 941 gfx::Size NativeWidgetAura::ConvertSizeToMonitor(const gfx::Size& size) const { |
944 return size.Scale(GetMonitor()->GetDeviceScaleFactor()); | 942 return size.Scale(GetMonitorScaleFactor()); |
945 } | 943 } |
946 | 944 |
947 gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { | 945 gfx::Rect NativeWidgetAura::ConvertRectToMonitor(const gfx::Rect& rect) const { |
948 float scale = GetMonitor()->GetDeviceScaleFactor(); | 946 float scale = GetMonitorScaleFactor(); |
949 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); | 947 return gfx::Rect(rect.origin().Scale(scale), rect.size().Scale(scale)); |
950 } | 948 } |
951 #endif | 949 #endif |
952 | 950 |
953 //////////////////////////////////////////////////////////////////////////////// | 951 //////////////////////////////////////////////////////////////////////////////// |
954 // Widget, public: | 952 // Widget, public: |
955 | 953 |
956 // static | 954 // static |
957 void Widget::NotifyLocaleChanged() { | 955 void Widget::NotifyLocaleChanged() { |
958 // Deliberately not implemented. | 956 // Deliberately not implemented. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 } | 1053 } |
1056 } | 1054 } |
1057 | 1055 |
1058 // static | 1056 // static |
1059 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1057 bool NativeWidgetPrivate::IsMouseButtonDown() { |
1060 return aura::Env::GetInstance()->is_mouse_button_down(); | 1058 return aura::Env::GetInstance()->is_mouse_button_down(); |
1061 } | 1059 } |
1062 | 1060 |
1063 } // namespace internal | 1061 } // namespace internal |
1064 } // namespace views | 1062 } // namespace views |
OLD | NEW |