| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 121 } |
| 122 | 122 |
| 123 NativeWidgetAura* host_; | 123 NativeWidgetAura* host_; |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); | 125 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 //////////////////////////////////////////////////////////////////////////////// | 128 //////////////////////////////////////////////////////////////////////////////// |
| 129 // NativeWidgetAura, public: | 129 // NativeWidgetAura, public: |
| 130 | 130 |
| 131 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | 131 NativeWidgetAura::NativeWidgetAura( |
| 132 internal::NativeWidgetDelegate* delegate, gfx::NativeView parent) |
| 132 : delegate_(delegate), | 133 : delegate_(delegate), |
| 133 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( | 134 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( |
| 134 ViewsDelegate::views_delegate ? | 135 ViewsDelegate::views_delegate ? |
| 135 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) : | 136 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this, parent): |
| 136 NULL)), | 137 NULL)), |
| 137 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | 138 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), |
| 138 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 139 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
| 139 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | 140 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), |
| 140 can_activate_(true), | 141 can_activate_(true), |
| 141 destroying_(false), | 142 destroying_(false), |
| 142 cursor_(gfx::kNullCursor), | 143 cursor_(gfx::kNullCursor), |
| 143 saved_window_state_(ui::SHOW_STATE_DEFAULT) { | 144 saved_window_state_(ui::SHOW_STATE_DEFAULT) { |
| 144 } | 145 } |
| 145 | 146 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 SetAlwaysOnTop(params.keep_on_top); | 207 SetAlwaysOnTop(params.keep_on_top); |
| 207 // If the parent is not specified, find the default parent for | 208 // If the parent is not specified, find the default parent for |
| 208 // the |window_| using the desired |window_bounds|. | 209 // the |window_| using the desired |window_bounds|. |
| 209 if (!parent) { | 210 if (!parent) { |
| 210 parent = aura::client::GetStackingClient()->GetDefaultParent( | 211 parent = aura::client::GetStackingClient()->GetDefaultParent( |
| 211 window_, window_bounds); | 212 window_, window_bounds); |
| 212 } else if (window_bounds == gfx::Rect()) { | 213 } else if (window_bounds == gfx::Rect()) { |
| 213 // If a parent is specified but no bounds are given, | 214 // If a parent is specified but no bounds are given, |
| 214 // use the origin of the parent's display so that the widget | 215 // use the origin of the parent's display so that the widget |
| 215 // will be added to the same display as the parent. | 216 // will be added to the same display as the parent. |
| 216 gfx::Rect bounds = gfx::Screen::GetDisplayNearestWindow(parent).bounds(); | 217 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> |
| 218 GetDisplayNearestWindow(parent).bounds(); |
| 217 window_bounds.set_origin(bounds.origin()); | 219 window_bounds.set_origin(bounds.origin()); |
| 218 } | 220 } |
| 219 window_->SetParent(parent); | 221 window_->SetParent(parent); |
| 220 } | 222 } |
| 221 | 223 |
| 222 // Wait to set the bounds until we have a parent. That way we can know our | 224 // Wait to set the bounds until we have a parent. That way we can know our |
| 223 // true state/bounds (the LayoutManager may enforce a particular | 225 // true state/bounds (the LayoutManager may enforce a particular |
| 224 // state/bounds). | 226 // state/bounds). |
| 225 if (IsMaximized()) | 227 if (IsMaximized()) |
| 226 SetRestoreBounds(window_, window_bounds); | 228 SetRestoreBounds(window_, window_bounds); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 356 |
| 355 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { | 357 internal::InputMethodDelegate* NativeWidgetAura::GetInputMethodDelegate() { |
| 356 return this; | 358 return this; |
| 357 } | 359 } |
| 358 | 360 |
| 359 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | 361 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { |
| 360 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); | 362 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); |
| 361 // When centering window, we take the intersection of the host and | 363 // When centering window, we take the intersection of the host and |
| 362 // the parent. We assume the root window represents the visible | 364 // the parent. We assume the root window represents the visible |
| 363 // rect of a single screen. | 365 // rect of a single screen. |
| 364 gfx::Rect work_area = | 366 gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> |
| 365 gfx::Screen::GetDisplayNearestWindow(window_).work_area(); | 367 GetDisplayNearestWindow(window_).work_area(); |
| 366 | 368 |
| 367 aura::client::ScreenPositionClient* screen_position_client = | 369 aura::client::ScreenPositionClient* screen_position_client = |
| 368 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | 370 aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
| 369 if (screen_position_client) { | 371 if (screen_position_client) { |
| 370 gfx::Point origin = work_area.origin(); | 372 gfx::Point origin = work_area.origin(); |
| 371 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), | 373 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), |
| 372 &origin); | 374 &origin); |
| 373 work_area.set_origin(origin); | 375 work_area.set_origin(origin); |
| 374 } | 376 } |
| 375 | 377 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 464 } |
| 463 return window_->GetBoundsInScreen(); | 465 return window_->GetBoundsInScreen(); |
| 464 } | 466 } |
| 465 | 467 |
| 466 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { | 468 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { |
| 467 aura::RootWindow* root = window_->GetRootWindow(); | 469 aura::RootWindow* root = window_->GetRootWindow(); |
| 468 if (root) { | 470 if (root) { |
| 469 aura::client::ScreenPositionClient* screen_position_client = | 471 aura::client::ScreenPositionClient* screen_position_client = |
| 470 aura::client::GetScreenPositionClient(root); | 472 aura::client::GetScreenPositionClient(root); |
| 471 if (screen_position_client) { | 473 if (screen_position_client) { |
| 472 gfx::Display dst_display = gfx::Screen::GetDisplayMatching(bounds); | 474 gfx::Display dst_display = |
| 475 gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); |
| 473 screen_position_client->SetBounds(window_, bounds, dst_display); | 476 screen_position_client->SetBounds(window_, bounds, dst_display); |
| 474 return; | 477 return; |
| 475 } | 478 } |
| 476 } | 479 } |
| 477 window_->SetBounds(bounds); | 480 window_->SetBounds(bounds); |
| 478 } | 481 } |
| 479 | 482 |
| 480 void NativeWidgetAura::SetSize(const gfx::Size& size) { | 483 void NativeWidgetAura::SetSize(const gfx::Size& size) { |
| 481 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 484 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
| 482 } | 485 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 cursor_client->SetCursor(cursor); | 664 cursor_client->SetCursor(cursor); |
| 662 } | 665 } |
| 663 | 666 |
| 664 void NativeWidgetAura::ClearNativeFocus() { | 667 void NativeWidgetAura::ClearNativeFocus() { |
| 665 if (window_ && window_->GetFocusManager() && | 668 if (window_ && window_->GetFocusManager() && |
| 666 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) | 669 window_->Contains(window_->GetFocusManager()->GetFocusedWindow())) |
| 667 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); | 670 window_->GetFocusManager()->SetFocusedWindow(window_, NULL); |
| 668 } | 671 } |
| 669 | 672 |
| 670 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | 673 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { |
| 671 return gfx::Screen::GetDisplayNearestWindow(GetNativeView()).work_area(); | 674 return gfx::Screen::GetScreenFor(GetNativeView())-> |
| 675 GetDisplayNearestWindow(GetNativeView()).work_area(); |
| 672 } | 676 } |
| 673 | 677 |
| 674 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | 678 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { |
| 675 if (!value) | 679 if (!value) |
| 676 active_window_observer_.reset(); | 680 active_window_observer_.reset(); |
| 677 else | 681 else |
| 678 active_window_observer_.reset(new ActiveWindowObserver(this)); | 682 active_window_observer_.reset(new ActiveWindowObserver(this)); |
| 679 } | 683 } |
| 680 | 684 |
| 681 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( | 685 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 return false; | 987 return false; |
| 984 } | 988 } |
| 985 | 989 |
| 986 namespace internal { | 990 namespace internal { |
| 987 | 991 |
| 988 //////////////////////////////////////////////////////////////////////////////// | 992 //////////////////////////////////////////////////////////////////////////////// |
| 989 // internal::NativeWidgetPrivate, public: | 993 // internal::NativeWidgetPrivate, public: |
| 990 | 994 |
| 991 // static | 995 // static |
| 992 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( | 996 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( |
| 993 internal::NativeWidgetDelegate* delegate) { | 997 internal::NativeWidgetDelegate* delegate, |
| 994 return new NativeWidgetAura(delegate); | 998 gfx::NativeView parent) { |
| 999 return new NativeWidgetAura(delegate, parent); |
| 995 } | 1000 } |
| 996 | 1001 |
| 997 // static | 1002 // static |
| 998 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( | 1003 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( |
| 999 gfx::NativeView native_view) { | 1004 gfx::NativeView native_view) { |
| 1000 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data()); | 1005 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data()); |
| 1001 } | 1006 } |
| 1002 | 1007 |
| 1003 // static | 1008 // static |
| 1004 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( | 1009 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 return aura::Env::GetInstance()->is_mouse_button_down(); | 1084 return aura::Env::GetInstance()->is_mouse_button_down(); |
| 1080 } | 1085 } |
| 1081 | 1086 |
| 1082 // static | 1087 // static |
| 1083 bool NativeWidgetPrivate::IsTouchDown() { | 1088 bool NativeWidgetPrivate::IsTouchDown() { |
| 1084 return aura::Env::GetInstance()->is_touch_down(); | 1089 return aura::Env::GetInstance()->is_touch_down(); |
| 1085 } | 1090 } |
| 1086 | 1091 |
| 1087 } // namespace internal | 1092 } // namespace internal |
| 1088 } // namespace views | 1093 } // namespace views |
| OLD | NEW |