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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 touch_ids_down_(0), | 142 touch_ids_down_(0), |
143 last_cursor_(ui::kCursorNull), | 143 last_cursor_(ui::kCursorNull), |
144 mouse_pressed_handler_(NULL), | 144 mouse_pressed_handler_(NULL), |
145 mouse_moved_handler_(NULL), | 145 mouse_moved_handler_(NULL), |
146 event_dispatch_target_(NULL), | 146 event_dispatch_target_(NULL), |
147 synthesize_mouse_move_(false), | 147 synthesize_mouse_move_(false), |
148 move_hold_count_(0), | 148 move_hold_count_(0), |
149 event_factory_(this), | 149 event_factory_(this), |
150 held_event_factory_(this), | 150 held_event_factory_(this), |
151 repostable_event_factory_(this) { | 151 repostable_event_factory_(this) { |
| 152 set_dispatcher(this); |
152 SetName("RootWindow"); | 153 SetName("RootWindow"); |
153 | 154 |
154 compositor_.reset(new ui::Compositor(host_->GetAcceleratedWidget())); | 155 compositor_.reset(new ui::Compositor(host_->GetAcceleratedWidget())); |
155 DCHECK(compositor_.get()); | 156 DCHECK(compositor_.get()); |
156 | 157 |
157 prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), | 158 prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), |
158 kRootWindowForAcceleratedWidget, | 159 kRootWindowForAcceleratedWidget, |
159 this)); | 160 this)); |
160 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); | 161 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); |
161 } | 162 } |
(...skipping 12 matching lines...) Expand all Loading... |
174 | 175 |
175 // Destroy child windows while we're still valid. This is also done by | 176 // Destroy child windows while we're still valid. This is also done by |
176 // ~Window, but by that time any calls to virtual methods overriden here (such | 177 // ~Window, but by that time any calls to virtual methods overriden here (such |
177 // as GetRootWindow()) result in Window's implementation. By destroying here | 178 // as GetRootWindow()) result in Window's implementation. By destroying here |
178 // we ensure GetRootWindow() still returns this. | 179 // we ensure GetRootWindow() still returns this. |
179 RemoveOrDestroyChildren(); | 180 RemoveOrDestroyChildren(); |
180 | 181 |
181 // Destroying/removing child windows may try to access |host_| (eg. | 182 // Destroying/removing child windows may try to access |host_| (eg. |
182 // GetAcceleratedWidget()) | 183 // GetAcceleratedWidget()) |
183 host_.reset(NULL); | 184 host_.reset(NULL); |
| 185 |
| 186 set_dispatcher(NULL); |
184 } | 187 } |
185 | 188 |
186 // static | 189 // static |
187 RootWindow* RootWindow::GetForAcceleratedWidget( | 190 RootWindow* RootWindow::GetForAcceleratedWidget( |
188 gfx::AcceleratedWidget widget) { | 191 gfx::AcceleratedWidget widget) { |
189 return reinterpret_cast<RootWindow*>( | 192 return reinterpret_cast<RootWindow*>( |
190 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); | 193 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); |
191 } | 194 } |
192 | 195 |
193 void RootWindow::Init() { | 196 void RootWindow::Init() { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 float scale = ui::GetDeviceScaleFactor(layer()); | 516 float scale = ui::GetDeviceScaleFactor(layer()); |
514 gfx::Transform transform; | 517 gfx::Transform transform; |
515 transform.Scale(scale, scale); | 518 transform.Scale(scale, scale); |
516 transform *= transformer_->GetTransform(); | 519 transform *= transformer_->GetTransform(); |
517 return transform; | 520 return transform; |
518 } | 521 } |
519 | 522 |
520 //////////////////////////////////////////////////////////////////////////////// | 523 //////////////////////////////////////////////////////////////////////////////// |
521 // RootWindow, Window overrides: | 524 // RootWindow, Window overrides: |
522 | 525 |
523 RootWindow* RootWindow::GetRootWindow() { | 526 Window* RootWindow::GetRootWindow() { |
524 return this; | 527 return this; |
525 } | 528 } |
526 | 529 |
527 const RootWindow* RootWindow::GetRootWindow() const { | 530 const Window* RootWindow::GetRootWindow() const { |
528 return this; | 531 return this; |
529 } | 532 } |
530 | 533 |
531 void RootWindow::SetTransform(const gfx::Transform& transform) { | 534 void RootWindow::SetTransform(const gfx::Transform& transform) { |
532 scoped_ptr<RootWindowTransformer> transformer( | 535 scoped_ptr<RootWindowTransformer> transformer( |
533 new SimpleRootWindowTransformer(this, transform)); | 536 new SimpleRootWindowTransformer(this, transform)); |
534 SetRootWindowTransformer(transformer.Pass()); | 537 SetRootWindowTransformer(transformer.Pass()); |
535 } | 538 } |
536 | 539 |
537 bool RootWindow::CanFocus() const { | 540 bool RootWindow::CanFocus() const { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 609 } |
607 | 610 |
608 void RootWindow::OnWindowAddedToRootWindow(Window* attached) { | 611 void RootWindow::OnWindowAddedToRootWindow(Window* attached) { |
609 if (attached->IsVisible() && | 612 if (attached->IsVisible() && |
610 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { | 613 attached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { |
611 PostMouseMoveEventAfterWindowChange(); | 614 PostMouseMoveEventAfterWindowChange(); |
612 } | 615 } |
613 } | 616 } |
614 | 617 |
615 void RootWindow::OnWindowRemovedFromRootWindow(Window* detached, | 618 void RootWindow::OnWindowRemovedFromRootWindow(Window* detached, |
616 RootWindow* new_root) { | 619 Window* new_root) { |
617 DCHECK(aura::client::GetCaptureWindow(this) != this); | 620 DCHECK(aura::client::GetCaptureWindow(this) != this); |
618 | 621 |
619 DispatchMouseExitToHidingWindow(detached); | 622 DispatchMouseExitToHidingWindow(detached); |
620 OnWindowHidden(detached, new_root ? WINDOW_MOVING : WINDOW_HIDDEN); | 623 OnWindowHidden(detached, new_root ? WINDOW_MOVING : WINDOW_HIDDEN); |
621 | 624 |
622 if (detached->IsVisible() && | 625 if (detached->IsVisible() && |
623 detached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { | 626 detached->ContainsPointInRoot(GetLastMouseLocationInRoot())) { |
624 PostMouseMoveEventAfterWindowChange(); | 627 PostMouseMoveEventAfterWindowChange(); |
625 } | 628 } |
626 } | 629 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 mouse_pressed_handler_ : client::GetCaptureWindow(this); | 933 mouse_pressed_handler_ : client::GetCaptureWindow(this); |
931 if (!target) | 934 if (!target) |
932 target = GetEventHandlerForPoint(event->location()); | 935 target = GetEventHandlerForPoint(event->location()); |
933 return DispatchMouseEventToTarget(event, target); | 936 return DispatchMouseEventToTarget(event, target); |
934 } | 937 } |
935 | 938 |
936 void RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { | 939 void RootWindow::DispatchMouseEventRepost(ui::MouseEvent* event) { |
937 if (event->type() != ui::ET_MOUSE_PRESSED) | 940 if (event->type() != ui::ET_MOUSE_PRESSED) |
938 return; | 941 return; |
939 Window* target = client::GetCaptureWindow(this); | 942 Window* target = client::GetCaptureWindow(this); |
940 RootWindow* root = this; | 943 WindowEventDispatcher* dispatcher = this; |
941 if (!target) { | 944 if (!target) { |
942 target = GetEventHandlerForPoint(event->location()); | 945 target = GetEventHandlerForPoint(event->location()); |
943 } else { | 946 } else { |
944 root = target->GetRootWindow(); | 947 dispatcher = target->GetDispatcher(); |
945 CHECK(root); // Capture window better be in valid root. | 948 CHECK(dispatcher); // Capture window better be in valid root. |
946 } | 949 } |
947 root->mouse_pressed_handler_ = NULL; | 950 dispatcher->mouse_pressed_handler_ = NULL; |
948 root->DispatchMouseEventToTarget(event, target); | 951 dispatcher->DispatchMouseEventToTarget(event, target); |
949 } | 952 } |
950 | 953 |
951 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, | 954 bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, |
952 Window* target) { | 955 Window* target) { |
953 client::CursorClient* cursor_client = client::GetCursorClient(this); | 956 client::CursorClient* cursor_client = client::GetCursorClient(this); |
954 if (cursor_client && | 957 if (cursor_client && |
955 !cursor_client->IsMouseEventsEnabled() && | 958 !cursor_client->IsMouseEventsEnabled() && |
956 (event->flags() & ui::EF_IS_SYNTHESIZED)) | 959 (event->flags() & ui::EF_IS_SYNTHESIZED)) |
957 return false; | 960 return false; |
958 | 961 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 } | 1188 } |
1186 | 1189 |
1187 gfx::Transform RootWindow::GetInverseRootTransform() const { | 1190 gfx::Transform RootWindow::GetInverseRootTransform() const { |
1188 float scale = ui::GetDeviceScaleFactor(layer()); | 1191 float scale = ui::GetDeviceScaleFactor(layer()); |
1189 gfx::Transform transform; | 1192 gfx::Transform transform; |
1190 transform.Scale(1.0f / scale, 1.0f / scale); | 1193 transform.Scale(1.0f / scale, 1.0f / scale); |
1191 return transformer_->GetInverseTransform() * transform; | 1194 return transformer_->GetInverseTransform() * transform; |
1192 } | 1195 } |
1193 | 1196 |
1194 } // namespace aura | 1197 } // namespace aura |
OLD | NEW |