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/aura/root_window.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 case ui::ET_GESTURE_TAP: | 61 case ui::ET_GESTURE_TAP: |
62 return NULL; | 62 return NULL; |
63 default: | 63 default: |
64 return target; | 64 return target; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 } // namespace | 68 } // namespace |
69 | 69 |
70 RootWindow* RootWindow::instance_ = NULL; | 70 RootWindow* RootWindow::instance_ = NULL; |
71 bool RootWindow::use_fullscreen_host_window_ = false; | |
72 bool RootWindow::hide_host_cursor_ = false; | 71 bool RootWindow::hide_host_cursor_ = false; |
73 | 72 |
74 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
75 // RootWindow, public: | 74 // RootWindow, public: |
76 | 75 |
77 RootWindow::RootWindow() | 76 RootWindow::RootWindow(const gfx::Rect& initial_bounds) |
78 : Window(NULL), | 77 : Window(NULL), |
79 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), | 78 host_(aura::RootWindowHost::Create(initial_bounds)), |
80 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 79 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
81 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 80 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
82 mouse_button_flags_(0), | 81 mouse_button_flags_(0), |
83 last_cursor_(kCursorNull), | 82 last_cursor_(kCursorNull), |
84 cursor_shown_(true), | 83 cursor_shown_(true), |
85 capture_window_(NULL), | 84 capture_window_(NULL), |
86 mouse_pressed_handler_(NULL), | 85 mouse_pressed_handler_(NULL), |
87 mouse_moved_handler_(NULL), | 86 mouse_moved_handler_(NULL), |
88 focused_window_(NULL), | 87 focused_window_(NULL), |
89 touch_event_handler_(NULL), | 88 touch_event_handler_(NULL), |
90 gesture_handler_(NULL), | 89 gesture_handler_(NULL), |
91 ALLOW_THIS_IN_INITIALIZER_LIST( | 90 ALLOW_THIS_IN_INITIALIZER_LIST( |
92 gesture_recognizer_(GestureRecognizer::Create(this))), | 91 gesture_recognizer_(GestureRecognizer::Create(this))), |
93 synthesize_mouse_move_(false), | 92 synthesize_mouse_move_(false), |
94 waiting_on_compositing_end_(false), | 93 waiting_on_compositing_end_(false), |
95 draw_on_compositing_end_(false), | 94 draw_on_compositing_end_(false), |
96 defer_draw_scheduling_(false), | 95 defer_draw_scheduling_(false), |
97 mouse_move_hold_count_(0), | 96 mouse_move_hold_count_(0), |
98 should_hold_mouse_moves_(false), | 97 should_hold_mouse_moves_(false), |
99 release_mouse_moves_after_draw_(false) { | 98 release_mouse_moves_after_draw_(false) { |
100 SetName("RootWindow"); | 99 SetName("RootWindow"); |
101 last_mouse_location_ = host_->QueryMouseLocation(); | 100 last_mouse_location_ = host_->QueryMouseLocation(); |
102 | 101 |
103 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( | 102 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( |
104 switches::kAuraDisableHoldMouseMoves); | 103 switches::kAuraDisableHoldMouseMoves); |
105 | 104 |
106 ui::Compositor::Initialize(false); | |
107 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), | 105 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), |
108 host_->GetBounds().size())); | 106 host_->GetBounds().size())); |
109 DCHECK(compositor_.get()); | 107 DCHECK(compositor_.get()); |
110 compositor_->AddObserver(this); | 108 compositor_->AddObserver(this); |
111 Init(); | 109 Init(); |
112 } | 110 } |
113 | 111 |
114 RootWindow::~RootWindow() { | 112 RootWindow::~RootWindow() { |
115 compositor_->RemoveObserver(this); | 113 compositor_->RemoveObserver(this); |
116 // Make sure to destroy the compositor before terminating so that state is | 114 // Make sure to destroy the compositor before terminating so that state is |
117 // cleared and we don't hit asserts. | 115 // cleared and we don't hit asserts. |
118 compositor_.reset(); | 116 compositor_.reset(); |
119 | 117 |
120 // Tear down in reverse. Frees any references held by the host. | 118 // Tear down in reverse. Frees any references held by the host. |
121 host_.reset(NULL); | 119 host_.reset(NULL); |
122 | 120 |
123 // An observer may have been added by an animation on the RootWindow. | 121 // An observer may have been added by an animation on the RootWindow. |
124 layer()->GetAnimator()->RemoveObserver(this); | 122 layer()->GetAnimator()->RemoveObserver(this); |
125 ui::Compositor::Terminate(); | |
126 if (instance_ == this) | 123 if (instance_ == this) |
piman
2012/03/20 00:31:37
Should this go away now that we can have more than
oshima
2012/03/20 02:29:58
looks like this is obsolete code. deleted.
| |
127 instance_ = NULL; | 124 instance_ = NULL; |
128 } | 125 } |
129 | 126 |
130 void RootWindow::ShowRootWindow() { | 127 void RootWindow::ShowRootWindow() { |
131 host_->Show(); | 128 host_->Show(); |
132 } | 129 } |
133 | 130 |
134 void RootWindow::SetHostSize(const gfx::Size& size) { | 131 void RootWindow::SetHostSize(const gfx::Size& size) { |
135 DispatchHeldMouseMove(); | 132 DispatchHeldMouseMove(); |
136 gfx::Rect bounds = host_->GetBounds(); | 133 gfx::Rect bounds = host_->GetBounds(); |
137 bounds.set_size(size); | 134 bounds.set_size(size); |
138 host_->SetBounds(bounds); | 135 host_->SetBounds(bounds); |
139 // Requery the location to constrain it within the new root window size. | 136 // Requery the location to constrain it within the new root window size. |
140 last_mouse_location_ = host_->QueryMouseLocation(); | 137 last_mouse_location_ = host_->QueryMouseLocation(); |
141 synthesize_mouse_move_ = false; | 138 synthesize_mouse_move_ = false; |
142 } | 139 } |
143 | 140 |
144 gfx::Size RootWindow::GetHostSize() const { | 141 gfx::Size RootWindow::GetHostSize() const { |
145 gfx::Rect rect(host_->GetBounds().size()); | 142 gfx::Rect rect(host_->GetBounds().size()); |
146 layer()->transform().TransformRect(&rect); | 143 layer()->transform().TransformRect(&rect); |
147 return rect.size(); | 144 return rect.size(); |
148 } | 145 } |
149 | 146 |
147 void RootWindow::SetHostBounds(const gfx::Rect& bounds) { | |
148 DispatchHeldMouseMove(); | |
149 host_->SetBounds(bounds); | |
150 // Requery the location to constrain it within the new root window size. | |
151 last_mouse_location_ = host_->QueryMouseLocation(); | |
152 synthesize_mouse_move_ = false; | |
153 } | |
154 | |
150 void RootWindow::SetCursor(gfx::NativeCursor cursor) { | 155 void RootWindow::SetCursor(gfx::NativeCursor cursor) { |
151 last_cursor_ = cursor; | 156 last_cursor_ = cursor; |
152 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 157 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
153 // so just pass everything along to the host. | 158 // so just pass everything along to the host. |
154 host_->SetCursor(cursor); | 159 host_->SetCursor(cursor); |
155 } | 160 } |
156 | 161 |
157 void RootWindow::ShowCursor(bool show) { | 162 void RootWindow::ShowCursor(bool show) { |
158 cursor_shown_ = show; | 163 cursor_shown_ = show; |
159 host_->ShowCursor(show); | 164 host_->ShowCursor(show); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 } | 435 } |
431 } | 436 } |
432 | 437 |
433 //////////////////////////////////////////////////////////////////////////////// | 438 //////////////////////////////////////////////////////////////////////////////// |
434 // RootWindow, Window overrides: | 439 // RootWindow, Window overrides: |
435 | 440 |
436 RootWindow* RootWindow::GetRootWindow() { | 441 RootWindow* RootWindow::GetRootWindow() { |
437 return this; | 442 return this; |
438 } | 443 } |
439 | 444 |
445 const RootWindow* RootWindow::GetRootWindow() const { | |
446 return this; | |
447 } | |
448 | |
440 void RootWindow::SetTransform(const ui::Transform& transform) { | 449 void RootWindow::SetTransform(const ui::Transform& transform) { |
441 Window::SetTransform(transform); | 450 Window::SetTransform(transform); |
442 | 451 |
443 // If the layer is not animating, then we need to update the host size | 452 // If the layer is not animating, then we need to update the host size |
444 // immediately. | 453 // immediately. |
445 if (!layer()->GetAnimator()->is_animating()) | 454 if (!layer()->GetAnimator()->is_animating()) |
446 OnHostResized(host_->GetBounds().size()); | 455 OnHostResized(host_->GetBounds().size()); |
447 } | 456 } |
448 | 457 |
449 //////////////////////////////////////////////////////////////////////////////// | 458 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 void RootWindow::DispatchHeldMouseMove() { | 836 void RootWindow::DispatchHeldMouseMove() { |
828 if (held_mouse_move_.get()) { | 837 if (held_mouse_move_.get()) { |
829 // If a mouse move has been synthesized, the target location is suspect, | 838 // If a mouse move has been synthesized, the target location is suspect, |
830 // so drop the held event. | 839 // so drop the held event. |
831 if (!synthesize_mouse_move_) | 840 if (!synthesize_mouse_move_) |
832 DispatchMouseEventImpl(held_mouse_move_.get()); | 841 DispatchMouseEventImpl(held_mouse_move_.get()); |
833 held_mouse_move_.reset(); | 842 held_mouse_move_.reset(); |
834 } | 843 } |
835 } | 844 } |
836 | 845 |
837 gfx::Rect RootWindow::GetInitialHostWindowBounds() const { | |
838 return Env::GetInstance()->monitor_manager()-> | |
839 GetMonitorNearestWindow(this)->bounds(); | |
840 } | |
841 | |
842 void RootWindow::PostMouseMoveEventAfterWindowChange() { | 846 void RootWindow::PostMouseMoveEventAfterWindowChange() { |
843 if (synthesize_mouse_move_) | 847 if (synthesize_mouse_move_) |
844 return; | 848 return; |
845 synthesize_mouse_move_ = true; | 849 synthesize_mouse_move_ = true; |
846 MessageLoop::current()->PostTask( | 850 MessageLoop::current()->PostTask( |
847 FROM_HERE, | 851 FROM_HERE, |
848 base::Bind(&RootWindow::SynthesizeMouseMoveEvent, | 852 base::Bind(&RootWindow::SynthesizeMouseMoveEvent, |
849 event_factory_.GetWeakPtr())); | 853 event_factory_.GetWeakPtr())); |
850 } | 854 } |
851 | 855 |
(...skipping 10 matching lines...) Expand all Loading... | |
862 // is currently broken. See/ crbug.com/107931. | 866 // is currently broken. See/ crbug.com/107931. |
863 MouseEvent event(ui::ET_MOUSE_MOVED, | 867 MouseEvent event(ui::ET_MOUSE_MOVED, |
864 orig_mouse_location, | 868 orig_mouse_location, |
865 orig_mouse_location, | 869 orig_mouse_location, |
866 ui::EF_IS_SYNTHESIZED); | 870 ui::EF_IS_SYNTHESIZED); |
867 DispatchMouseEvent(&event); | 871 DispatchMouseEvent(&event); |
868 #endif | 872 #endif |
869 } | 873 } |
870 | 874 |
871 } // namespace aura | 875 } // namespace aura |
OLD | NEW |