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_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { | 76 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { |
77 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | 77 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
83 // NativeWidgetAura, public: | 83 // NativeWidgetAura, public: |
84 | 84 |
85 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 85 NativeWidgetAura::NativeWidgetAura( |
| 86 internal::NativeWidgetDelegate* delegate, gfx::NativeView parent) |
86 : delegate_(delegate), | 87 : delegate_(delegate), |
87 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( | 88 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( |
88 ViewsDelegate::views_delegate ? | 89 ViewsDelegate::views_delegate ? |
89 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) : | 90 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this, parent): |
90 NULL)), | 91 NULL)), |
91 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 92 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
92 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 93 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
93 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 94 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
94 can_activate_(true), | 95 can_activate_(true), |
95 destroying_(false), | 96 destroying_(false), |
96 cursor_(gfx::kNullCursor), | 97 cursor_(gfx::kNullCursor), |
97 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 98 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
98 } | 99 } |
99 | 100 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 SetAlwaysOnTop(params.keep_on_top); | 161 SetAlwaysOnTop(params.keep_on_top); |
161 // If the parent is not specified, find the default parent for | 162 // If the parent is not specified, find the default parent for |
162 // the |window_| using the desired |window_bounds|. | 163 // the |window_| using the desired |window_bounds|. |
163 if (!parent) { | 164 if (!parent) { |
164 parent = aura::client::GetStackingClient()->GetDefaultParent( | 165 parent = aura::client::GetStackingClient()->GetDefaultParent( |
165 window_, window_bounds); | 166 window_, window_bounds); |
166 } else if (window_bounds == gfx::Rect()) { | 167 } else if (window_bounds == gfx::Rect()) { |
167 // If a parent is specified but no bounds are given, | 168 // If a parent is specified but no bounds are given, |
168 // use the origin of the parent's display so that the widget | 169 // use the origin of the parent's display so that the widget |
169 // will be added to the same display as the parent. | 170 // will be added to the same display as the parent. |
170 gfx::Rect bounds = gfx::Screen::GetDisplayNearestWindow(parent).bounds(); | 171 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> |
| 172 GetDisplayNearestWindow(parent).bounds(); |
171 window_bounds.set_origin(bounds.origin()); | 173 window_bounds.set_origin(bounds.origin()); |
172 } | 174 } |
173 window_->SetParent(parent); | 175 window_->SetParent(parent); |
174 } | 176 } |
175 | 177 |
176 // Wait to set the bounds until we have a parent. That way we can know our | 178 // Wait to set the bounds until we have a parent. That way we can know our |
177 // true state/bounds (the LayoutManager may enforce a particular | 179 // true state/bounds (the LayoutManager may enforce a particular |
178 // state/bounds). | 180 // state/bounds). |
179 if (IsMaximized()) | 181 if (IsMaximized()) |
180 SetRestoreBounds(window_, window_bounds); | 182 SetRestoreBounds(window_, window_bounds); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 310 |
309 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { | 311 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { |
310 return this; | 312 return this; |
311 } | 313 } |
312 | 314 |
313 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | 315 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { |
314 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); | 316 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); |
315 // When centering window, we take the intersection of the host and | 317 // When centering window, we take the intersection of the host and |
316 // the parent. We assume the root window represents the visible | 318 // the parent. We assume the root window represents the visible |
317 // rect of a single screen. | 319 // rect of a single screen. |
318 gfx::Rect work_area = | 320 gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> |
319 gfx::Screen::GetDisplayNearestWindow(window_).work_area(); | 321 GetDisplayNearestWindow(window_).work_area(); |
320 | 322 |
321 aura::client::ScreenPositionClient* screen_position_client = | 323 aura::client::ScreenPositionClient* screen_position_client = |
322 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | 324 aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
323 if (screen_position_client) { | 325 if (screen_position_client) { |
324 gfx::Point origin = work_area.origin(); | 326 gfx::Point origin = work_area.origin(); |
325 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), | 327 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), |
326 &origin); | 328 &origin); |
327 work_area.set_origin(origin); | 329 work_area.set_origin(origin); |
328 } | 330 } |
329 | 331 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 418 } |
417 return window_->GetBoundsInScreen(); | 419 return window_->GetBoundsInScreen(); |
418 } | 420 } |
419 | 421 |
420 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { | 422 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { |
421 aura::RootWindow* root = window_->GetRootWindow(); | 423 aura::RootWindow* root = window_->GetRootWindow(); |
422 if (root) { | 424 if (root) { |
423 aura::client::ScreenPositionClient* screen_position_client = | 425 aura::client::ScreenPositionClient* screen_position_client = |
424 aura::client::GetScreenPositionClient(root); | 426 aura::client::GetScreenPositionClient(root); |
425 if (screen_position_client) { | 427 if (screen_position_client) { |
426 gfx::Display dst_display = gfx::Screen::GetDisplayMatching(bounds); | 428 gfx::Display dst_display = |
| 429 gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); |
427 screen_position_client->SetBounds(window_, bounds, dst_display); | 430 screen_position_client->SetBounds(window_, bounds, dst_display); |
428 return; | 431 return; |
429 } | 432 } |
430 } | 433 } |
431 window_->SetBounds(bounds); | 434 window_->SetBounds(bounds); |
432 } | 435 } |
433 | 436 |
434 void NativeWidgetAura::SetSize(const gfx::Size& size) { | 437 void NativeWidgetAura::SetSize(const gfx::Size& size) { |
435 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 438 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
436 } | 439 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 cursor_client->SetCursor(cursor); | 618 cursor_client->SetCursor(cursor); |
616 } | 619 } |
617 | 620 |
618 void NativeWidgetAura::ClearNativeFocus() { | 621 void NativeWidgetAura::ClearNativeFocus() { |
619 if (window_ && window_->GetFocusManager() && | 622 if (window_ && window_->GetFocusManager() && |
620 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) | 623 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) |
621 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); | 624 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); |
622 } | 625 } |
623 | 626 |
624 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 627 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
625 return gfx::Screen::GetDisplayNearestWindow(GetNativeView()).work_area(); | 628 return gfx::Screen::GetScreenFor(GetNativeView())-> |
| 629 GetDisplayNearestWindow(GetNativeView()).work_area(); |
626 } | 630 } |
627 | 631 |
628 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | 632 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { |
629 if (!value) { | 633 if (!value) { |
630 active_window_observer_.reset(); | 634 active_window_observer_.reset(); |
631 } else { | 635 } else { |
632 active_window_observer_.reset( | 636 active_window_observer_.reset( |
633 new NativeWidgetAuraWindowObserver(window_, delegate_)); | 637 new NativeWidgetAuraWindowObserver(window_, delegate_)); |
634 } | 638 } |
635 } | 639 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 return false; | 943 return false; |
940 } | 944 } |
941 | 945 |
942 namespace internal { | 946 namespace internal { |
943 | 947 |
944 //////////////////////////////////////////////////////////////////////////////// | 948 //////////////////////////////////////////////////////////////////////////////// |
945 // internal::NativeWidgetPrivate, public: | 949 // internal::NativeWidgetPrivate, public: |
946 | 950 |
947 // static | 951 // static |
948 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( | 952 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( |
949 internal::NativeWidgetDelegate* delegate) { | 953 internal::NativeWidgetDelegate* delegate, |
950 return new NativeWidgetAura(delegate); | 954 gfx::NativeView parent) { |
| 955 return new NativeWidgetAura(delegate, parent); |
951 } | 956 } |
952 | 957 |
953 // static | 958 // static |
954 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( | 959 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( |
955 gfx::NativeView native_view) { | 960 gfx::NativeView native_view) { |
956 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data()); | 961 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data()); |
957 } | 962 } |
958 | 963 |
959 // static | 964 // static |
960 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( | 965 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 return aura::Env::GetInstance()->is_mouse_button_down(); | 1040 return aura::Env::GetInstance()->is_mouse_button_down(); |
1036 } | 1041 } |
1037 | 1042 |
1038 // static | 1043 // static |
1039 bool NativeWidgetPrivate::IsTouchDown() { | 1044 bool NativeWidgetPrivate::IsTouchDown() { |
1040 return aura::Env::GetInstance()->is_touch_down(); | 1045 return aura::Env::GetInstance()->is_touch_down(); |
1041 } | 1046 } |
1042 | 1047 |
1043 } // namespace internal | 1048 } // namespace internal |
1044 } // namespace views | 1049 } // namespace views |
OLD | NEW |