Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: ui/views/widget/native_widget_aura.cc

Issue 10083057: Revert 132856 - Aura/ash split: Remove hacks and get chrome linking without ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_helper_aura.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:mergeinfo
OLDNEW
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"
11 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
12 #include "ui/aura/client/dispatcher_client.h"
12 #include "ui/aura/client/drag_drop_client.h" 13 #include "ui/aura/client/drag_drop_client.h"
13 #include "ui/aura/client/window_move_client.h" 14 #include "ui/aura/client/window_move_client.h"
14 #include "ui/aura/client/window_types.h" 15 #include "ui/aura/client/window_types.h"
16 #include "ui/aura/desktop/desktop_activation_client.h"
17 #include "ui/aura/desktop/desktop_dispatcher_client.h"
18 #include "ui/aura/desktop/desktop_root_window_event_filter.h"
15 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
16 #include "ui/aura/event.h" 20 #include "ui/aura/event.h"
17 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
18 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
19 #include "ui/aura/window_observer.h" 23 #include "ui/aura/window_observer.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 24 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
22 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/compositor/layer.h" 27 #include "ui/gfx/compositor/layer.h"
24 #include "ui/gfx/font.h" 28 #include "ui/gfx/font.h"
25 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
26 #include "ui/views/drag_utils.h" 30 #include "ui/views/drag_utils.h"
27 #include "ui/views/ime/input_method_bridge.h" 31 #include "ui/views/ime/input_method_bridge.h"
28 #include "ui/views/views_delegate.h"
29 #include "ui/views/widget/drop_helper.h" 32 #include "ui/views/widget/drop_helper.h"
30 #include "ui/views/widget/native_widget_delegate.h" 33 #include "ui/views/widget/native_widget_delegate.h"
31 #include "ui/views/widget/native_widget_helper_aura.h"
32 #include "ui/views/widget/root_view.h" 34 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/tooltip_manager_aura.h" 35 #include "ui/views/widget/tooltip_manager_aura.h"
34 #include "ui/views/widget/widget_delegate.h" 36 #include "ui/views/widget/widget_delegate.h"
35 37
36 #if defined(OS_WIN) 38 #if defined(OS_WIN)
37 #include "base/win/scoped_gdi_object.h" 39 #include "base/win/scoped_gdi_object.h"
38 #include "base/win/win_util.h" 40 #include "base/win/win_util.h"
39 #include "ui/base/l10n/l10n_util_win.h" 41 #include "ui/base/l10n/l10n_util_win.h"
40 #endif 42 #endif
41 43
42 #if defined(ENABLE_DIP) 44 #if defined(ENABLE_DIP)
43 #include "ui/aura/monitor.h" 45 #include "ui/aura/monitor.h"
44 #include "ui/aura/monitor_manager.h" 46 #include "ui/aura/monitor_manager.h"
45 #endif 47 #endif
46 48
47 namespace views { 49 namespace views {
48 50
51 bool NativeWidgetAura::g_aura_desktop_hax = false;
52
49 namespace { 53 namespace {
50 54
51 aura::client::WindowType GetAuraWindowTypeForWidgetType( 55 aura::client::WindowType GetAuraWindowTypeForWidgetType(
52 Widget::InitParams::Type type) { 56 Widget::InitParams::Type type) {
53 switch (type) { 57 switch (type) {
54 case Widget::InitParams::TYPE_WINDOW: 58 case Widget::InitParams::TYPE_WINDOW:
55 return aura::client::WINDOW_TYPE_NORMAL; 59 return aura::client::WINDOW_TYPE_NORMAL;
56 case Widget::InitParams::TYPE_PANEL: 60 case Widget::InitParams::TYPE_PANEL:
57 return aura::client::WINDOW_TYPE_PANEL; 61 return aura::client::WINDOW_TYPE_PANEL;
58 case Widget::InitParams::TYPE_CONTROL: 62 case Widget::InitParams::TYPE_CONTROL:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 NativeWidgetAura* host_; 132 NativeWidgetAura* host_;
129 133
130 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver); 134 DISALLOW_COPY_AND_ASSIGN(ActiveWindowObserver);
131 }; 135 };
132 136
133 //////////////////////////////////////////////////////////////////////////////// 137 ////////////////////////////////////////////////////////////////////////////////
134 // NativeWidgetAura, public: 138 // NativeWidgetAura, public:
135 139
136 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 140 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
137 : delegate_(delegate), 141 : delegate_(delegate),
138 ALLOW_THIS_IN_INITIALIZER_LIST(desktop_helper_( 142 root_window_(NULL),
139 ViewsDelegate::views_delegate ?
140 ViewsDelegate::views_delegate->CreateNativeWidgetHelper(this) :
141 NULL)),
142 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 143 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
143 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 144 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
144 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), 145 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
145 can_activate_(true), 146 can_activate_(true),
146 cursor_(gfx::kNullCursor), 147 cursor_(gfx::kNullCursor),
147 saved_window_state_(ui::SHOW_STATE_DEFAULT) { 148 saved_window_state_(ui::SHOW_STATE_DEFAULT) {
148 } 149 }
149 150
150 NativeWidgetAura::~NativeWidgetAura() { 151 NativeWidgetAura::~NativeWidgetAura() {
151 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 152 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
(...skipping 13 matching lines...) Expand all
165 #else 166 #else
166 return gfx::Font(); 167 return gfx::Font();
167 #endif 168 #endif
168 } 169 }
169 170
170 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
171 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: 172 // NativeWidgetAura, internal::NativeWidgetPrivate implementation:
172 173
173 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { 174 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
174 ownership_ = params.ownership; 175 ownership_ = params.ownership;
176 // TODO(erg): What kind of windows do we want to have their own root windows?
177 if (g_aura_desktop_hax) {
178 gfx::Rect bounds = params.bounds;
179 if (bounds.IsEmpty()) {
180 // We must pass some non-zero value when we initialize a RootWindow. This
181 // will probably be SetBounds()ed soon.
182 bounds.set_size(gfx::Size(100, 100));
183 }
184 root_window_.reset(new aura::RootWindow(bounds));
185 root_window_->SetEventFilter(
186 new aura::DesktopRootWindowEventFilter(root_window_.get()));
187 root_window_->AddRootWindowObserver(this);
175 188
176 if (desktop_helper_.get()) 189 aura::client::SetActivationClient(
177 desktop_helper_->PreInitialize(params); 190 root_window_.get(),
191 new aura::DesktopActivationClient(root_window_.get()));
192 aura::client::SetDispatcherClient(root_window_.get(),
193 new aura::DesktopDispatcherClient);
194 }
178 195
179 window_->set_user_data(this); 196 window_->set_user_data(this);
180 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 197 window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
181 window_->SetProperty(aura::client::kShowStateKey, params.show_state); 198 window_->SetProperty(aura::client::kShowStateKey, params.show_state);
182 if (params.type == Widget::InitParams::TYPE_BUBBLE) 199 if (params.type == Widget::InitParams::TYPE_BUBBLE)
183 aura::client::SetHideOnDeactivate(window_, true); 200 aura::client::SetHideOnDeactivate(window_, true);
184 window_->SetTransparent(params.transparent); 201 window_->SetTransparent(params.transparent);
185 window_->Init(params.layer_type); 202 window_->Init(params.layer_type);
186 if (params.type == Widget::InitParams::TYPE_CONTROL) 203 if (params.type == Widget::InitParams::TYPE_CONTROL)
187 window_->Show(); 204 window_->Show();
188 205
189 delegate_->OnNativeWidgetCreated(); 206 delegate_->OnNativeWidgetCreated();
190 if (desktop_helper_.get() && desktop_helper_->GetRootWindow()) { 207 if (root_window_.get()) {
191 window_->SetParent(desktop_helper_->GetRootWindow()); 208 window_->SetParent(root_window_.get());
192 } else if (params.child) { 209 } else if (params.child) {
193 window_->SetParent(params.GetParent()); 210 window_->SetParent(params.GetParent());
194 } else { 211 } else {
195 // Set up the transient child before the window is added. This way the 212 // Set up the transient child before the window is added. This way the
196 // LayoutManager knows the window has a transient parent. 213 // LayoutManager knows the window has a transient parent.
197 gfx::NativeView parent = params.GetParent(); 214 gfx::NativeView parent = params.GetParent();
198 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { 215 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) {
199 parent->AddTransientChild(window_); 216 parent->AddTransientChild(window_);
200 217
201 // TODO(erg): The StackingClient interface implies that there is only a 218 // TODO(erg): The StackingClient interface implies that there is only a
202 // single root window. Solving this would require setting a stacking 219 // single root window. Solving this would require setting a stacking
203 // client per root window instead. For now, we hax our way around this by 220 // client per root window instead. For now, we hax our way around this by
204 // forcing the parent to be the root window instead of passing NULL as 221 // forcing the parent to be the root window instead of passing NULL as
205 // the parent which will dispatch to the stacking client. 222 // the parent which will dispatch to the stacking client.
206 if (desktop_helper_.get()) 223 if (g_aura_desktop_hax)
207 parent = parent->GetRootWindow(); 224 parent = parent->GetRootWindow();
208 else 225 else
209 parent = NULL; 226 parent = NULL;
210 } 227 }
211 // SetAlwaysOnTop before SetParent so that always-on-top container is used. 228 // SetAlwaysOnTop before SetParent so that always-on-top container is used.
212 SetAlwaysOnTop(params.keep_on_top); 229 SetAlwaysOnTop(params.keep_on_top);
213 window_->SetParent(parent); 230 window_->SetParent(parent);
214 } 231 }
215 232
216 // Wait to set the bounds until we have a parent. That way we can know our 233 // Wait to set the bounds until we have a parent. That way we can know our
(...skipping 12 matching lines...) Expand all
229 #endif // !defined(OS_MACOSX) 246 #endif // !defined(OS_MACOSX)
230 247
231 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); 248 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
232 if (params.type != Widget::InitParams::TYPE_TOOLTIP && 249 if (params.type != Widget::InitParams::TYPE_TOOLTIP &&
233 params.type != Widget::InitParams::TYPE_POPUP) { 250 params.type != Widget::InitParams::TYPE_POPUP) {
234 aura::client::SetDragDropDelegate(window_, this); 251 aura::client::SetDragDropDelegate(window_, this);
235 } 252 }
236 253
237 aura::client::SetActivationDelegate(window_, this); 254 aura::client::SetActivationDelegate(window_, this);
238 255
239 // TODO(erg): Move this somewhere else? 256 if (root_window_.get())
240 if (desktop_helper_.get()) 257 root_window_->ShowRootWindow();
241 desktop_helper_->ShowRootWindow();
242 } 258 }
243 259
244 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { 260 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() {
245 return NULL; 261 return NULL;
246 } 262 }
247 263
248 void NativeWidgetAura::UpdateFrameAfterFrameChange() { 264 void NativeWidgetAura::UpdateFrameAfterFrameChange() {
249 } 265 }
250 266
251 bool NativeWidgetAura::ShouldUseNativeFrame() const { 267 bool NativeWidgetAura::ShouldUseNativeFrame() const {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 return ConvertRectFromMonitor( 464 return ConvertRectFromMonitor(
449 restore_bounds ? *restore_bounds : window_->bounds()); 465 restore_bounds ? *restore_bounds : window_->bounds());
450 #else 466 #else
451 return restore_bounds ? *restore_bounds : window_->bounds(); 467 return restore_bounds ? *restore_bounds : window_->bounds();
452 #endif 468 #endif
453 } 469 }
454 470
455 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) { 471 void NativeWidgetAura::SetBounds(const gfx::Rect& in_bounds) {
456 gfx::Rect bounds = in_bounds; 472 gfx::Rect bounds = in_bounds;
457 473
458 if (desktop_helper_.get()) 474 if (root_window_.get() && !bounds.IsEmpty()) {
459 bounds = desktop_helper_->ModifyAndSetBounds(bounds); 475 root_window_->SetHostBounds(bounds);
476 bounds.set_x(0);
477 bounds.set_y(0);
478 }
460 #if defined(ENABLE_DIP) 479 #if defined(ENABLE_DIP)
461 bounds = ConvertRectToMonitor(bounds); 480 bounds = ConvertRectToMonitor(bounds);
462 #endif 481 #endif
463 window_->SetBounds(bounds); 482 window_->SetBounds(bounds);
464 } 483 }
465 484
466 void NativeWidgetAura::SetSize(const gfx::Size& size) { 485 void NativeWidgetAura::SetSize(const gfx::Size& size) {
467 #if defined(ENABLE_DIP) 486 #if defined(ENABLE_DIP)
468 gfx::Size monitor_size = ConvertSizeToMonitor(size); 487 gfx::Size monitor_size = ConvertSizeToMonitor(size);
469 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size)); 488 window_->SetBounds(gfx::Rect(window_->bounds().origin(), monitor_size));
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 delegate_->OnNativeWidgetDestroyed(); 866 delegate_->OnNativeWidgetDestroyed();
848 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 867 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
849 delete this; 868 delete this;
850 } 869 }
851 870
852 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { 871 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) {
853 delegate_->OnNativeWidgetVisibilityChanged(visible); 872 delegate_->OnNativeWidgetVisibilityChanged(visible);
854 } 873 }
855 874
856 //////////////////////////////////////////////////////////////////////////////// 875 ////////////////////////////////////////////////////////////////////////////////
876 // NativeWidgetAura, aura::RootWindowObserver implementation:
877
878 void NativeWidgetAura::OnRootWindowResized(const aura::RootWindow* root,
879 const gfx::Size& old_size) {
880 // This case can only happen if we have our own aura::RootWindow*. When that
881 // happens, our main window should be at the origin and sized to the
882 // RootWindow.
883 DCHECK_EQ(root, root_window_.get());
884 SetBounds(gfx::Rect(root->GetHostSize()));
885 }
886
887 void NativeWidgetAura::OnRootWindowHostClosed(const aura::RootWindow* root) {
888 DCHECK_EQ(root, root_window_.get());
889 GetWidget()->Close();
890 }
891
892 ////////////////////////////////////////////////////////////////////////////////
857 // NativeWidgetAura, aura::ActivationDelegate implementation: 893 // NativeWidgetAura, aura::ActivationDelegate implementation:
858 894
859 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) { 895 bool NativeWidgetAura::ShouldActivate(const aura::Event* event) {
860 return can_activate_ && delegate_->CanActivate(); 896 return can_activate_ && delegate_->CanActivate();
861 } 897 }
862 898
863 void NativeWidgetAura::OnActivated() { 899 void NativeWidgetAura::OnActivated() {
864 if (GetWidget()->HasFocusManager()) 900 if (GetWidget()->HasFocusManager())
865 GetWidget()->GetFocusManager()->RestoreFocusedView(); 901 GetWidget()->GetFocusManager()->RestoreFocusedView();
866 delegate_->OnNativeWidgetActivationChanged(true); 902 delegate_->OnNativeWidgetActivationChanged(true);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 } 1085 }
1050 } 1086 }
1051 1087
1052 // static 1088 // static
1053 bool NativeWidgetPrivate::IsMouseButtonDown() { 1089 bool NativeWidgetPrivate::IsMouseButtonDown() {
1054 return aura::Env::GetInstance()->is_mouse_button_down(); 1090 return aura::Env::GetInstance()->is_mouse_button_down();
1055 } 1091 }
1056 1092
1057 } // namespace internal 1093 } // namespace internal
1058 } // namespace views 1094 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_helper_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698