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

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

Issue 11369220: Move the desktop aura classes into a desktop subdir to make the gyp simpler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/desktop_native_widget_aura.h"
6
7 #include "base/bind.h"
8 #include "ui/aura/client/stacking_client.h"
9 #include "ui/aura/focus_manager.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/aura/root_window_host.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_property.h"
14 #include "ui/base/hit_test.h"
15 #include "ui/base/native_theme/native_theme.h"
16 #include "ui/compositor/layer.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/views/ime/input_method.h"
19 #include "ui/views/widget/desktop_root_window_host.h"
20 #include "ui/views/widget/native_widget_aura_window_observer.h"
21 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_aura_utils.h"
23
24 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(VIEWS_EXPORT,
25 views::DesktopNativeWidgetAura*);
26
27 namespace views {
28
29 DEFINE_WINDOW_PROPERTY_KEY(DesktopNativeWidgetAura*,
30 kDesktopNativeWidgetAuraKey, NULL);
31
32 namespace {
33
34 class DesktopNativeWidgetAuraStackingClient :
35 public aura::client::StackingClient {
36 public:
37 explicit DesktopNativeWidgetAuraStackingClient(aura::RootWindow* root_window)
38 : root_window_(root_window) {
39 aura::client::SetStackingClient(root_window_, this);
40 }
41 virtual ~DesktopNativeWidgetAuraStackingClient() {
42 aura::client::SetStackingClient(root_window_, NULL);
43 }
44
45 // Overridden from client::StackingClient:
46 virtual aura::Window* GetDefaultParent(aura::Window* window,
47 const gfx::Rect& bounds) OVERRIDE {
48 return root_window_;
49 }
50
51 private:
52 aura::RootWindow* root_window_;
53
54 DISALLOW_COPY_AND_ASSIGN(DesktopNativeWidgetAuraStackingClient);
55 };
56
57 } // namespace
58
59 ////////////////////////////////////////////////////////////////////////////////
60 // DesktopNativeWidgetAura, public:
61
62 DesktopNativeWidgetAura::DesktopNativeWidgetAura(
63 internal::NativeWidgetDelegate* delegate)
64 : ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
65 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
66 can_activate_(true),
67 desktop_root_window_host_(NULL),
68 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
69 native_widget_delegate_(delegate) {
70 window_->SetProperty(kDesktopNativeWidgetAuraKey, this);
71 }
72
73 DesktopNativeWidgetAura::~DesktopNativeWidgetAura() {
74 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
75 delete native_widget_delegate_;
76 else
77 CloseNow();
78 }
79
80 // static
81 DesktopNativeWidgetAura* DesktopNativeWidgetAura::ForWindow(
82 aura::Window* window) {
83 return window->GetProperty(kDesktopNativeWidgetAuraKey);
84 }
85
86 void DesktopNativeWidgetAura::OnHostClosed() {
87 // This will, through a long list of callbacks, trigger |root_window_| going
88 // away. See OnWindowDestroyed()
89 delete window_;
90 }
91
92 ////////////////////////////////////////////////////////////////////////////////
93 // DesktopNativeWidgetAura, internal::NativeWidgetPrivate implementation:
94
95 void DesktopNativeWidgetAura::InitNativeWidget(
96 const Widget::InitParams& params) {
97 ownership_ = params.ownership;
98
99 window_->set_user_data(this);
100 window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
101 window_->SetTransparent(true);
102 window_->Init(params.layer_type);
103 window_->Show();
104
105 desktop_root_window_host_ = params.desktop_root_window_host ?
106 params.desktop_root_window_host :
107 DesktopRootWindowHost::Create(native_widget_delegate_,
108 this, params.bounds);
109 root_window_.reset(
110 desktop_root_window_host_->Init(window_, params));
111 stacking_client_.reset(
112 new DesktopNativeWidgetAuraStackingClient(root_window_.get()));
113
114 aura::client::SetActivationDelegate(window_, this);
115 }
116
117 NonClientFrameView* DesktopNativeWidgetAura::CreateNonClientFrameView() {
118 return desktop_root_window_host_->CreateNonClientFrameView();
119 }
120
121 bool DesktopNativeWidgetAura::ShouldUseNativeFrame() const {
122 return desktop_root_window_host_->ShouldUseNativeFrame();
123 }
124
125 void DesktopNativeWidgetAura::FrameTypeChanged() {
126 desktop_root_window_host_->FrameTypeChanged();
127 }
128
129 Widget* DesktopNativeWidgetAura::GetWidget() {
130 return native_widget_delegate_->AsWidget();
131 }
132
133 const Widget* DesktopNativeWidgetAura::GetWidget() const {
134 return native_widget_delegate_->AsWidget();
135 }
136
137 gfx::NativeView DesktopNativeWidgetAura::GetNativeView() const {
138 return window_;
139 }
140
141 gfx::NativeWindow DesktopNativeWidgetAura::GetNativeWindow() const {
142 return window_;
143 }
144
145 Widget* DesktopNativeWidgetAura::GetTopLevelWidget() {
146 return GetWidget();
147 }
148
149 const ui::Compositor* DesktopNativeWidgetAura::GetCompositor() const {
150 return window_->layer()->GetCompositor();
151 }
152
153 ui::Compositor* DesktopNativeWidgetAura::GetCompositor() {
154 return window_->layer()->GetCompositor();
155 }
156
157 gfx::Vector2d DesktopNativeWidgetAura::CalculateOffsetToAncestorWithLayer(
158 ui::Layer** layer_parent) {
159 if (layer_parent)
160 *layer_parent = window_->layer();
161 return gfx::Vector2d();
162 }
163
164 void DesktopNativeWidgetAura::ViewRemoved(View* view) {
165 }
166
167 void DesktopNativeWidgetAura::SetNativeWindowProperty(const char* name,
168 void* value) {
169 window_->SetNativeWindowProperty(name, value);
170 }
171
172 void* DesktopNativeWidgetAura::GetNativeWindowProperty(const char* name) const {
173 return window_->GetNativeWindowProperty(name);
174 }
175
176 TooltipManager* DesktopNativeWidgetAura::GetTooltipManager() const {
177 return NULL;
178 }
179
180 bool DesktopNativeWidgetAura::IsScreenReaderActive() const {
181 return false;
182 }
183
184 void DesktopNativeWidgetAura::SendNativeAccessibilityEvent(
185 View* view,
186 ui::AccessibilityTypes::Event event_type) {
187 }
188
189 void DesktopNativeWidgetAura::SetCapture() {
190 window_->SetCapture();
191 // aura::Window doesn't implicitly update capture on the RootWindowHost, so
192 // we have to do that manually.
193 if (!desktop_root_window_host_->HasCapture())
194 window_->GetRootWindow()->SetNativeCapture();
195 }
196
197 void DesktopNativeWidgetAura::ReleaseCapture() {
198 window_->ReleaseCapture();
199 // aura::Window doesn't implicitly update capture on the RootWindowHost, so
200 // we have to do that manually.
201 if (desktop_root_window_host_->HasCapture())
202 window_->GetRootWindow()->ReleaseNativeCapture();
203 }
204
205 bool DesktopNativeWidgetAura::HasCapture() const {
206 return window_->HasCapture() && desktop_root_window_host_->HasCapture();
207 }
208
209 InputMethod* DesktopNativeWidgetAura::CreateInputMethod() {
210 return desktop_root_window_host_->CreateInputMethod();
211 }
212
213 internal::InputMethodDelegate*
214 DesktopNativeWidgetAura::GetInputMethodDelegate() {
215 return desktop_root_window_host_->GetInputMethodDelegate();
216 }
217
218 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) {
219 desktop_root_window_host_->CenterWindow(size);
220 }
221
222 void DesktopNativeWidgetAura::GetWindowPlacement(
223 gfx::Rect* bounds,
224 ui::WindowShowState* maximized) const {
225 desktop_root_window_host_->GetWindowPlacement(bounds, maximized);
226 }
227
228 void DesktopNativeWidgetAura::SetWindowTitle(const string16& title) {
229 desktop_root_window_host_->SetWindowTitle(title);
230 }
231
232 void DesktopNativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon,
233 const gfx::ImageSkia& app_icon) {
234 }
235
236 void DesktopNativeWidgetAura::SetAccessibleName(const string16& name) {
237 }
238
239 void DesktopNativeWidgetAura::SetAccessibleRole(
240 ui::AccessibilityTypes::Role role) {
241 }
242
243 void DesktopNativeWidgetAura::SetAccessibleState(
244 ui::AccessibilityTypes::State state) {
245 }
246
247 void DesktopNativeWidgetAura::InitModalType(ui::ModalType modal_type) {
248 }
249
250 gfx::Rect DesktopNativeWidgetAura::GetWindowBoundsInScreen() const {
251 return desktop_root_window_host_->GetWindowBoundsInScreen();
252 }
253
254 gfx::Rect DesktopNativeWidgetAura::GetClientAreaBoundsInScreen() const {
255 return desktop_root_window_host_->GetClientAreaBoundsInScreen();
256 }
257
258 gfx::Rect DesktopNativeWidgetAura::GetRestoredBounds() const {
259 return desktop_root_window_host_->GetRestoredBounds();
260 }
261
262 void DesktopNativeWidgetAura::SetBounds(const gfx::Rect& bounds) {
263 desktop_root_window_host_->AsRootWindowHost()->SetBounds(bounds);
264 }
265
266 void DesktopNativeWidgetAura::SetSize(const gfx::Size& size) {
267 desktop_root_window_host_->SetSize(size);
268 }
269
270 void DesktopNativeWidgetAura::StackAbove(gfx::NativeView native_view) {
271 }
272
273 void DesktopNativeWidgetAura::StackAtTop() {
274 }
275
276 void DesktopNativeWidgetAura::StackBelow(gfx::NativeView native_view) {
277 }
278
279 void DesktopNativeWidgetAura::SetShape(gfx::NativeRegion shape) {
280 desktop_root_window_host_->SetShape(shape);
281 }
282
283 void DesktopNativeWidgetAura::Close() {
284 desktop_root_window_host_->Close();
285 }
286
287 void DesktopNativeWidgetAura::CloseNow() {
288 desktop_root_window_host_->CloseNow();
289 }
290
291 void DesktopNativeWidgetAura::Show() {
292 desktop_root_window_host_->AsRootWindowHost()->Show();
293 }
294
295 void DesktopNativeWidgetAura::Hide() {
296 desktop_root_window_host_->AsRootWindowHost()->Hide();
297 }
298
299 void DesktopNativeWidgetAura::ShowMaximizedWithBounds(
300 const gfx::Rect& restored_bounds) {
301 desktop_root_window_host_->ShowMaximizedWithBounds(restored_bounds);
302 }
303
304 void DesktopNativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
305 desktop_root_window_host_->ShowWindowWithState(state);
306 }
307
308 bool DesktopNativeWidgetAura::IsVisible() const {
309 return desktop_root_window_host_->IsVisible();
310 }
311
312 void DesktopNativeWidgetAura::Activate() {
313 desktop_root_window_host_->Activate();
314 }
315
316 void DesktopNativeWidgetAura::Deactivate() {
317 desktop_root_window_host_->Deactivate();
318 }
319
320 bool DesktopNativeWidgetAura::IsActive() const {
321 return desktop_root_window_host_->IsActive();
322 }
323
324 void DesktopNativeWidgetAura::SetAlwaysOnTop(bool always_on_top) {
325 desktop_root_window_host_->SetAlwaysOnTop(always_on_top);
326 }
327
328 void DesktopNativeWidgetAura::Maximize() {
329 desktop_root_window_host_->Maximize();
330 }
331
332 void DesktopNativeWidgetAura::Minimize() {
333 desktop_root_window_host_->Minimize();
334 }
335
336 bool DesktopNativeWidgetAura::IsMaximized() const {
337 return desktop_root_window_host_->IsMaximized();
338 }
339
340 bool DesktopNativeWidgetAura::IsMinimized() const {
341 return desktop_root_window_host_->IsMinimized();
342 }
343
344 void DesktopNativeWidgetAura::Restore() {
345 desktop_root_window_host_->Restore();
346 }
347
348 void DesktopNativeWidgetAura::SetFullscreen(bool fullscreen) {
349 desktop_root_window_host_->SetFullscreen(fullscreen);
350 }
351
352 bool DesktopNativeWidgetAura::IsFullscreen() const {
353 return desktop_root_window_host_->IsFullscreen();
354 }
355
356 void DesktopNativeWidgetAura::SetOpacity(unsigned char opacity) {
357 desktop_root_window_host_->SetOpacity(opacity);
358 }
359
360 void DesktopNativeWidgetAura::SetUseDragFrame(bool use_drag_frame) {
361 }
362
363 void DesktopNativeWidgetAura::FlashFrame(bool flash_frame) {
364 desktop_root_window_host_->FlashFrame(flash_frame);
365 }
366
367 bool DesktopNativeWidgetAura::IsAccessibleWidget() const {
368 return false;
369 }
370
371 void DesktopNativeWidgetAura::RunShellDrag(View* view,
372 const ui::OSExchangeData& data,
373 const gfx::Point& location,
374 int operation,
375 ui::DragDropTypes::DragEventSource source) {
376 }
377
378 void DesktopNativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
379 if (window_)
380 window_->SchedulePaintInRect(rect);
381 }
382
383 void DesktopNativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
384 desktop_root_window_host_->AsRootWindowHost()->SetCursor(cursor);
385 }
386
387 void DesktopNativeWidgetAura::ClearNativeFocus() {
388 desktop_root_window_host_->ClearNativeFocus();
389 }
390
391 gfx::Rect DesktopNativeWidgetAura::GetWorkAreaBoundsInScreen() const {
392 return desktop_root_window_host_->GetWorkAreaBoundsInScreen();
393 }
394
395 void DesktopNativeWidgetAura::SetInactiveRenderingDisabled(bool value) {
396 if (!value) {
397 active_window_observer_.reset();
398 } else {
399 active_window_observer_.reset(
400 new NativeWidgetAuraWindowObserver(window_, native_widget_delegate_));
401 }
402 }
403
404 Widget::MoveLoopResult DesktopNativeWidgetAura::RunMoveLoop(
405 const gfx::Vector2d& drag_offset) {
406 return desktop_root_window_host_->RunMoveLoop(drag_offset);
407 }
408
409 void DesktopNativeWidgetAura::EndMoveLoop() {
410 desktop_root_window_host_->EndMoveLoop();
411 }
412
413 void DesktopNativeWidgetAura::SetVisibilityChangedAnimationsEnabled(
414 bool value) {
415 desktop_root_window_host_->SetVisibilityChangedAnimationsEnabled(value);
416 }
417
418 ui::NativeTheme* DesktopNativeWidgetAura::GetNativeTheme() const {
419 return DesktopRootWindowHost::GetNativeTheme(window_);
420 }
421
422 ////////////////////////////////////////////////////////////////////////////////
423 // DesktopNativeWidgetAura, aura::WindowDelegate implementation:
424
425 gfx::Size DesktopNativeWidgetAura::GetMinimumSize() const {
426 return native_widget_delegate_->GetMinimumSize();
427 }
428
429 void DesktopNativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
430 const gfx::Rect& new_bounds) {
431 if (old_bounds.origin() != new_bounds.origin())
432 native_widget_delegate_->OnNativeWidgetMove();
433 if (old_bounds.size() != new_bounds.size())
434 native_widget_delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
435 }
436
437 void DesktopNativeWidgetAura::OnFocus(aura::Window* old_focused_window) {
438 desktop_root_window_host_->OnNativeWidgetFocus();
439 native_widget_delegate_->OnNativeFocus(old_focused_window);
440 }
441
442 void DesktopNativeWidgetAura::OnBlur() {
443 if (GetWidget()->HasFocusManager())
444 GetWidget()->GetFocusManager()->StoreFocusedView();
445 desktop_root_window_host_->OnNativeWidgetBlur();
446 native_widget_delegate_->OnNativeBlur(
447 window_->GetFocusManager()->GetFocusedWindow());
448 }
449
450 gfx::NativeCursor DesktopNativeWidgetAura::GetCursor(const gfx::Point& point) {
451 return gfx::kNullCursor;
452 }
453
454 int DesktopNativeWidgetAura::GetNonClientComponent(
455 const gfx::Point& point) const {
456 return native_widget_delegate_->GetNonClientComponent(point);
457 }
458
459 bool DesktopNativeWidgetAura::ShouldDescendIntoChildForEventHandling(
460 aura::Window* child,
461 const gfx::Point& location) {
462 return true;
463 }
464
465 bool DesktopNativeWidgetAura::CanFocus() {
466 return true;
467 }
468
469 void DesktopNativeWidgetAura::OnCaptureLost() {
470 native_widget_delegate_->OnMouseCaptureLost();
471 }
472
473 void DesktopNativeWidgetAura::OnPaint(gfx::Canvas* canvas) {
474 native_widget_delegate_->OnNativeWidgetPaint(canvas);
475 }
476
477 void DesktopNativeWidgetAura::OnDeviceScaleFactorChanged(
478 float device_scale_factor) {
479 }
480
481 void DesktopNativeWidgetAura::OnWindowDestroying() {
482 native_widget_delegate_->OnNativeWidgetDestroying();
483 }
484
485 void DesktopNativeWidgetAura::OnWindowDestroyed() {
486 window_ = NULL;
487 native_widget_delegate_->OnNativeWidgetDestroyed();
488 // TODO(beng): I think we should only do this if widget owns native widget.
489 // Verify and if untrue remove this comment.
490 delete this;
491 }
492
493 void DesktopNativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) {
494 }
495
496 bool DesktopNativeWidgetAura::HasHitTestMask() const {
497 return native_widget_delegate_->HasHitTestMask();
498 }
499
500 void DesktopNativeWidgetAura::GetHitTestMask(gfx::Path* mask) const {
501 native_widget_delegate_->GetHitTestMask(mask);
502 }
503
504 scoped_refptr<ui::Texture> DesktopNativeWidgetAura::CopyTexture() {
505 // The layer we create doesn't have an external texture, so this should never
506 // get invoked.
507 NOTREACHED();
508 return scoped_refptr<ui::Texture>();
509 }
510
511 ////////////////////////////////////////////////////////////////////////////////
512 // DesktopNativeWidgetAura, ui::EventHandler implementation:
513
514 ui::EventResult DesktopNativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) {
515 if (event->is_char()) {
516 // If a ui::InputMethod object is attached to the root window, character
517 // events are handled inside the object and are not passed to this function.
518 // If such object is not attached, character events might be sent (e.g. on
519 // Windows). In this case, we just skip these.
520 return ui::ER_UNHANDLED;
521 }
522 // Renderer may send a key event back to us if the key event wasn't handled,
523 // and the window may be invisible by that time.
524 if (!window_->IsVisible())
525 return ui::ER_UNHANDLED;
526
527 if (native_widget_delegate_->OnKeyEvent(*event))
528 return ui::ER_HANDLED;
529
530 if (GetWidget()->HasFocusManager() &&
531 !GetWidget()->GetFocusManager()->OnKeyEvent(*event))
532 return ui::ER_HANDLED;
533
534 return ui::ER_UNHANDLED;
535 }
536
537 ui::EventResult DesktopNativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) {
538 DCHECK(window_->IsVisible());
539 if (event->type() == ui::ET_MOUSEWHEEL) {
540 return native_widget_delegate_->OnMouseEvent(*event) ?
541 ui::ER_HANDLED : ui::ER_UNHANDLED;
542 }
543
544 if (event->type() == ui::ET_SCROLL) {
545 if (native_widget_delegate_->OnMouseEvent(*event))
546 return ui::ER_HANDLED;
547
548 // Convert unprocessed scroll events into wheel events.
549 ui::MouseWheelEvent mwe(*static_cast<ui::ScrollEvent*>(event));
550 return native_widget_delegate_->OnMouseEvent(mwe) ?
551 ui::ER_HANDLED : ui::ER_UNHANDLED;
552 }
553 return native_widget_delegate_->OnMouseEvent(*event) ?
554 ui::ER_HANDLED : ui::ER_UNHANDLED;
555 }
556
557 ui::EventResult DesktopNativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) {
558 return native_widget_delegate_->OnTouchEvent(event);
559 }
560
561 ui::EventResult DesktopNativeWidgetAura::OnGestureEvent(
562 ui::GestureEvent* event) {
563 return native_widget_delegate_->OnGestureEvent(event);
564 }
565
566 ////////////////////////////////////////////////////////////////////////////////
567 // DesktopNativeWidgetAura, aura::ActivationDelegate implementation:
568
569 bool DesktopNativeWidgetAura::ShouldActivate(const ui::Event* event) {
570 return can_activate_ && native_widget_delegate_->CanActivate();
571 }
572
573 void DesktopNativeWidgetAura::OnActivated() {
574 if (GetWidget()->HasFocusManager())
575 GetWidget()->GetFocusManager()->RestoreFocusedView();
576 native_widget_delegate_->OnNativeWidgetActivationChanged(true);
577 if (IsVisible() && GetWidget()->non_client_view())
578 GetWidget()->non_client_view()->SchedulePaint();
579 }
580
581 void DesktopNativeWidgetAura::OnLostActive() {
582 native_widget_delegate_->OnNativeWidgetActivationChanged(false);
583 if (IsVisible() && GetWidget()->non_client_view())
584 GetWidget()->non_client_view()->SchedulePaint();
585 }
586
587 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_native_widget_aura.h ('k') | ui/views/widget/desktop_root_window_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698