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/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 GetLayersToStack(child->children()[i], layers); | 155 GetLayersToStack(child->children()[i], layers); |
156 } | 156 } |
157 | 157 |
158 } // namespace | 158 } // namespace |
159 | 159 |
160 class ScopedCursorHider { | 160 class ScopedCursorHider { |
161 public: | 161 public: |
162 explicit ScopedCursorHider(Window* window) | 162 explicit ScopedCursorHider(Window* window) |
163 : window_(window), | 163 : window_(window), |
164 hid_cursor_(false) { | 164 hid_cursor_(false) { |
165 if (!window_->HasDispatcher()) | 165 if (!window_->IsRootWindow()) |
166 return; | 166 return; |
167 const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains( | 167 const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains( |
168 Env::GetInstance()->last_mouse_location()); | 168 Env::GetInstance()->last_mouse_location()); |
169 client::CursorClient* cursor_client = client::GetCursorClient(window_); | 169 client::CursorClient* cursor_client = client::GetCursorClient(window_); |
170 if (cursor_is_in_bounds && cursor_client && | 170 if (cursor_is_in_bounds && cursor_client && |
171 cursor_client->IsCursorVisible()) { | 171 cursor_client->IsCursorVisible()) { |
172 cursor_client->HideCursor(); | 172 cursor_client->HideCursor(); |
173 hid_cursor_ = true; | 173 hid_cursor_ = true; |
174 } | 174 } |
175 } | 175 } |
176 ~ScopedCursorHider() { | 176 ~ScopedCursorHider() { |
177 if (!window_->HasDispatcher()) | 177 if (!window_->IsRootWindow()) |
178 return; | 178 return; |
179 | 179 |
180 // Update the device scale factor of the cursor client only when the last | 180 // Update the device scale factor of the cursor client only when the last |
181 // mouse location is on this root window. | 181 // mouse location is on this root window. |
182 if (hid_cursor_) { | 182 if (hid_cursor_) { |
183 client::CursorClient* cursor_client = client::GetCursorClient(window_); | 183 client::CursorClient* cursor_client = client::GetCursorClient(window_); |
184 if (cursor_client) { | 184 if (cursor_client) { |
185 const gfx::Display& display = | 185 const gfx::Display& display = |
186 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow( | 186 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow( |
187 window_); | 187 window_); |
188 cursor_client->SetDisplay(display); | 188 cursor_client->SetDisplay(display); |
189 cursor_client->ShowCursor(); | 189 cursor_client->ShowCursor(); |
190 } | 190 } |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 private: | 194 private: |
195 Window* window_; | 195 Window* window_; |
196 bool hid_cursor_; | 196 bool hid_cursor_; |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider); | 198 DISALLOW_COPY_AND_ASSIGN(ScopedCursorHider); |
199 }; | 199 }; |
200 | 200 |
201 Window::Window(WindowDelegate* delegate) | 201 Window::Window(WindowDelegate* delegate) |
202 : dispatcher_(NULL), | 202 : host_(NULL), |
203 type_(ui::wm::WINDOW_TYPE_UNKNOWN), | 203 type_(ui::wm::WINDOW_TYPE_UNKNOWN), |
204 owned_by_parent_(true), | 204 owned_by_parent_(true), |
205 delegate_(delegate), | 205 delegate_(delegate), |
206 parent_(NULL), | 206 parent_(NULL), |
207 visible_(false), | 207 visible_(false), |
208 id_(-1), | 208 id_(-1), |
209 transparent_(false), | 209 transparent_(false), |
210 user_data_(NULL), | 210 user_data_(NULL), |
211 ignore_events_(false), | 211 ignore_events_(false), |
212 // Don't notify newly added observers during notification. This causes | 212 // Don't notify newly added observers during notification. This causes |
213 // problems for code that adds an observer as part of an observer | 213 // problems for code that adds an observer as part of an observer |
214 // notification (such as the workspace code). | 214 // notification (such as the workspace code). |
215 observers_(ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY) { | 215 observers_(ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY) { |
216 set_target_handler(delegate_); | 216 set_target_handler(delegate_); |
217 } | 217 } |
218 | 218 |
219 Window::~Window() { | 219 Window::~Window() { |
220 // |layer_| can be NULL during tests, or if this Window is layerless. | 220 // |layer_| can be NULL during tests, or if this Window is layerless. |
221 if (layer_) | 221 if (layer_) |
222 layer_->SuppressPaint(); | 222 layer_->SuppressPaint(); |
223 | 223 |
224 // Let the delegate know we're in the processing of destroying. | 224 // Let the delegate know we're in the processing of destroying. |
225 if (delegate_) | 225 if (delegate_) |
226 delegate_->OnWindowDestroying(this); | 226 delegate_->OnWindowDestroying(this); |
227 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); | 227 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); |
228 | 228 |
229 // Let the root know so that it can remove any references to us. | 229 // Let the root know so that it can remove any references to us. |
230 WindowEventDispatcher* dispatcher = GetDispatcher(); | 230 WindowTreeHost* host = GetHost(); |
231 if (dispatcher) | 231 if (host) |
232 dispatcher->OnWindowDestroying(this); | 232 host->dispatcher()->OnWindowDestroying(this); |
233 | 233 |
234 // Then destroy the children. | 234 // Then destroy the children. |
235 RemoveOrDestroyChildren(); | 235 RemoveOrDestroyChildren(); |
236 | 236 |
237 // The window needs to be removed from the parent before calling the | 237 // The window needs to be removed from the parent before calling the |
238 // WindowDestroyed callbacks of delegate and the observers. | 238 // WindowDestroyed callbacks of delegate and the observers. |
239 if (parent_) | 239 if (parent_) |
240 parent_->RemoveChild(this); | 240 parent_->RemoveChild(this); |
241 | 241 |
242 if (delegate_) | 242 if (delegate_) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if (layer_) | 336 if (layer_) |
337 layer_->SetFillsBoundsOpaquely(!transparent_); | 337 layer_->SetFillsBoundsOpaquely(!transparent_); |
338 } | 338 } |
339 | 339 |
340 Window* Window::GetRootWindow() { | 340 Window* Window::GetRootWindow() { |
341 return const_cast<Window*>( | 341 return const_cast<Window*>( |
342 static_cast<const Window*>(this)->GetRootWindow()); | 342 static_cast<const Window*>(this)->GetRootWindow()); |
343 } | 343 } |
344 | 344 |
345 const Window* Window::GetRootWindow() const { | 345 const Window* Window::GetRootWindow() const { |
346 return dispatcher_ ? this : parent_ ? parent_->GetRootWindow() : NULL; | 346 return IsRootWindow() ? this : parent_ ? parent_->GetRootWindow() : NULL; |
347 } | 347 } |
348 | 348 |
349 WindowEventDispatcher* Window::GetDispatcher() { | 349 WindowTreeHost* Window::GetHost() { |
350 return const_cast<WindowEventDispatcher*>(const_cast<const Window*>(this)-> | 350 return const_cast<WindowTreeHost*>(const_cast<const Window*>(this)-> |
351 GetDispatcher()); | 351 GetHost()); |
352 } | 352 } |
353 | 353 |
354 const WindowEventDispatcher* Window::GetDispatcher() const { | 354 const WindowTreeHost* Window::GetHost() const { |
355 const Window* root_window = GetRootWindow(); | 355 const Window* root_window = GetRootWindow(); |
356 return root_window ? root_window->dispatcher_ : NULL; | 356 return root_window ? root_window->host_ : NULL; |
357 } | 357 } |
358 | 358 |
359 void Window::Show() { | 359 void Window::Show() { |
360 SetVisible(true); | 360 SetVisible(true); |
361 } | 361 } |
362 | 362 |
363 void Window::Hide() { | 363 void Window::Hide() { |
364 // RootWindow::OnVisibilityChanged will call ReleaseCapture. | 364 // RootWindow::OnVisibilityChanged will call ReleaseCapture. |
365 SetVisible(false); | 365 SetVisible(false); |
366 } | 366 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 return bounds; | 405 return bounds; |
406 } | 406 } |
407 | 407 |
408 void Window::SetTransform(const gfx::Transform& transform) { | 408 void Window::SetTransform(const gfx::Transform& transform) { |
409 if (!layer_) { | 409 if (!layer_) { |
410 // Transforms aren't supported on layerless windows. | 410 // Transforms aren't supported on layerless windows. |
411 NOTREACHED(); | 411 NOTREACHED(); |
412 return; | 412 return; |
413 } | 413 } |
414 WindowEventDispatcher* dispatcher = GetDispatcher(); | 414 WindowEventDispatcher* dispatcher = GetHost()->dispatcher(); |
415 bool contained_mouse = IsVisible() && dispatcher && | 415 bool contained_mouse = IsVisible() && dispatcher && |
416 ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); | 416 ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); |
417 layer_->SetTransform(transform); | 417 layer_->SetTransform(transform); |
418 if (dispatcher) | 418 if (dispatcher) |
419 dispatcher->OnWindowTransformed(this, contained_mouse); | 419 dispatcher->OnWindowTransformed(this, contained_mouse); |
420 } | 420 } |
421 | 421 |
422 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 422 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
423 if (layout_manager == layout_manager_) | 423 if (layout_manager == layout_manager_) |
424 return; | 424 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 child->parent_ = this; | 541 child->parent_ = this; |
542 | 542 |
543 children_.push_back(child); | 543 children_.push_back(child); |
544 if (layout_manager_) | 544 if (layout_manager_) |
545 layout_manager_->OnWindowAddedToLayout(child); | 545 layout_manager_->OnWindowAddedToLayout(child); |
546 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); | 546 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); |
547 child->OnParentChanged(); | 547 child->OnParentChanged(); |
548 | 548 |
549 Window* root_window = GetRootWindow(); | 549 Window* root_window = GetRootWindow(); |
550 if (root_window && old_root != root_window) { | 550 if (root_window && old_root != root_window) { |
551 root_window->GetDispatcher()->OnWindowAddedToRootWindow(child); | 551 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); |
552 child->NotifyAddedToRootWindow(); | 552 child->NotifyAddedToRootWindow(); |
553 } | 553 } |
554 | 554 |
555 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED; | 555 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED; |
556 NotifyWindowHierarchyChange(params); | 556 NotifyWindowHierarchyChange(params); |
557 } | 557 } |
558 | 558 |
559 void Window::RemoveChild(Window* child) { | 559 void Window::RemoveChild(Window* child) { |
560 WindowObserver::HierarchyChangeParams params; | 560 WindowObserver::HierarchyChangeParams params; |
561 params.target = child; | 561 params.target = child; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 } else { | 623 } else { |
624 ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point); | 624 ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point); |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 void Window::MoveCursorTo(const gfx::Point& point_in_window) { | 628 void Window::MoveCursorTo(const gfx::Point& point_in_window) { |
629 Window* root_window = GetRootWindow(); | 629 Window* root_window = GetRootWindow(); |
630 DCHECK(root_window); | 630 DCHECK(root_window); |
631 gfx::Point point_in_root(point_in_window); | 631 gfx::Point point_in_root(point_in_window); |
632 ConvertPointToTarget(this, root_window, &point_in_root); | 632 ConvertPointToTarget(this, root_window, &point_in_root); |
633 root_window->GetDispatcher()->host()->MoveCursorTo(point_in_root); | 633 root_window->GetHost()->MoveCursorTo(point_in_root); |
634 } | 634 } |
635 | 635 |
636 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { | 636 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { |
637 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; | 637 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; |
638 } | 638 } |
639 | 639 |
640 void Window::SetEventFilter(ui::EventHandler* event_filter) { | 640 void Window::SetEventFilter(ui::EventHandler* event_filter) { |
641 if (event_filter_) | 641 if (event_filter_) |
642 RemovePreTargetHandler(event_filter_.get()); | 642 RemovePreTargetHandler(event_filter_.get()); |
643 event_filter_.reset(event_filter); | 643 event_filter_.reset(event_filter); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 DCHECK(client); | 698 DCHECK(client); |
699 client->FocusWindow(NULL); | 699 client->FocusWindow(NULL); |
700 } | 700 } |
701 | 701 |
702 bool Window::HasFocus() const { | 702 bool Window::HasFocus() const { |
703 client::FocusClient* client = client::GetFocusClient(this); | 703 client::FocusClient* client = client::GetFocusClient(this); |
704 return client && client->GetFocusedWindow() == this; | 704 return client && client->GetFocusedWindow() == this; |
705 } | 705 } |
706 | 706 |
707 bool Window::CanFocus() const { | 707 bool Window::CanFocus() const { |
708 if (dispatcher_) | 708 if (IsRootWindow()) |
709 return IsVisible(); | 709 return IsVisible(); |
710 | 710 |
711 // NOTE: as part of focusing the window the ActivationClient may make the | 711 // NOTE: as part of focusing the window the ActivationClient may make the |
712 // window visible (by way of making a hidden ancestor visible). For this | 712 // window visible (by way of making a hidden ancestor visible). For this |
713 // reason we can't check visibility here and assume the client is doing it. | 713 // reason we can't check visibility here and assume the client is doing it. |
714 if (!parent_ || (delegate_ && !delegate_->CanFocus())) | 714 if (!parent_ || (delegate_ && !delegate_->CanFocus())) |
715 return false; | 715 return false; |
716 | 716 |
717 // The client may forbid certain windows from receiving focus at a given point | 717 // The client may forbid certain windows from receiving focus at a given point |
718 // in time. | 718 // in time. |
719 client::EventClient* client = client::GetEventClient(GetRootWindow()); | 719 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
720 if (client && !client->CanProcessEventsWithinSubtree(this)) | 720 if (client && !client->CanProcessEventsWithinSubtree(this)) |
721 return false; | 721 return false; |
722 | 722 |
723 return parent_->CanFocus(); | 723 return parent_->CanFocus(); |
724 } | 724 } |
725 | 725 |
726 bool Window::CanReceiveEvents() const { | 726 bool Window::CanReceiveEvents() const { |
727 if (dispatcher_) | 727 if (IsRootWindow()) |
728 return IsVisible(); | 728 return IsVisible(); |
729 | 729 |
730 // The client may forbid certain windows from receiving events at a given | 730 // The client may forbid certain windows from receiving events at a given |
731 // point in time. | 731 // point in time. |
732 client::EventClient* client = client::GetEventClient(GetRootWindow()); | 732 client::EventClient* client = client::GetEventClient(GetRootWindow()); |
733 if (client && !client->CanProcessEventsWithinSubtree(this)) | 733 if (client && !client->CanProcessEventsWithinSubtree(this)) |
734 return false; | 734 return false; |
735 | 735 |
736 return parent_ && IsVisible() && parent_->CanReceiveEvents(); | 736 return parent_ && IsVisible() && parent_->CanReceiveEvents(); |
737 } | 737 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 SetPropertyInternal( | 772 SetPropertyInternal( |
773 key, key, NULL, reinterpret_cast<int64>(value), 0); | 773 key, key, NULL, reinterpret_cast<int64>(value), 0); |
774 } | 774 } |
775 | 775 |
776 void* Window::GetNativeWindowProperty(const char* key) const { | 776 void* Window::GetNativeWindowProperty(const char* key) const { |
777 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); | 777 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); |
778 } | 778 } |
779 | 779 |
780 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { | 780 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { |
781 ScopedCursorHider hider(this); | 781 ScopedCursorHider hider(this); |
782 if (dispatcher_) | 782 if (IsRootWindow()) |
783 dispatcher_->host()->OnDeviceScaleFactorChanged(device_scale_factor); | 783 host_->OnDeviceScaleFactorChanged(device_scale_factor); |
784 if (delegate_) | 784 if (delegate_) |
785 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 785 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
786 } | 786 } |
787 | 787 |
788 #if !defined(NDEBUG) | 788 #if !defined(NDEBUG) |
789 std::string Window::GetDebugInfo() const { | 789 std::string Window::GetDebugInfo() const { |
790 return base::StringPrintf( | 790 return base::StringPrintf( |
791 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", | 791 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", |
792 name().empty() ? "Unknown" : name().c_str(), id(), | 792 name().empty() ? "Unknown" : name().c_str(), id(), |
793 bounds().x(), bounds().y(), bounds().width(), bounds().height(), | 793 bounds().x(), bounds().y(), bounds().width(), bounds().height(), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 } | 913 } |
914 | 914 |
915 void Window::SetVisible(bool visible) { | 915 void Window::SetVisible(bool visible) { |
916 if ((layer_ && visible == layer_->GetTargetVisibility()) || | 916 if ((layer_ && visible == layer_->GetTargetVisibility()) || |
917 (!layer_ && visible == visible_)) | 917 (!layer_ && visible == visible_)) |
918 return; // No change. | 918 return; // No change. |
919 | 919 |
920 FOR_EACH_OBSERVER(WindowObserver, observers_, | 920 FOR_EACH_OBSERVER(WindowObserver, observers_, |
921 OnWindowVisibilityChanging(this, visible)); | 921 OnWindowVisibilityChanging(this, visible)); |
922 | 922 |
923 WindowEventDispatcher* dispatcher = GetDispatcher(); | 923 WindowTreeHost* host = GetHost(); |
924 if (dispatcher) | 924 if (host) |
925 dispatcher->DispatchMouseExitToHidingWindow(this); | 925 host->dispatcher()->DispatchMouseExitToHidingWindow(this); |
926 | 926 |
927 client::VisibilityClient* visibility_client = | 927 client::VisibilityClient* visibility_client = |
928 client::GetVisibilityClient(this); | 928 client::GetVisibilityClient(this); |
929 if (visibility_client) | 929 if (visibility_client) |
930 visibility_client->UpdateLayerVisibility(this, visible); | 930 visibility_client->UpdateLayerVisibility(this, visible); |
931 else if (layer_) | 931 else if (layer_) |
932 layer_->SetVisible(visible); | 932 layer_->SetVisible(visible); |
933 visible_ = visible; | 933 visible_ = visible; |
934 SchedulePaint(); | 934 SchedulePaint(); |
935 if (parent_ && parent_->layout_manager_) | 935 if (parent_ && parent_->layout_manager_) |
936 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); | 936 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); |
937 | 937 |
938 if (delegate_) | 938 if (delegate_) |
939 delegate_->OnWindowTargetVisibilityChanged(visible); | 939 delegate_->OnWindowTargetVisibilityChanged(visible); |
940 | 940 |
941 NotifyWindowVisibilityChanged(this, visible); | 941 NotifyWindowVisibilityChanged(this, visible); |
942 | 942 |
943 if (dispatcher) | 943 if (host) |
944 dispatcher->OnWindowVisibilityChanged(this, visible); | 944 host->dispatcher()->OnWindowVisibilityChanged(this, visible); |
945 } | 945 } |
946 | 946 |
947 void Window::SchedulePaint() { | 947 void Window::SchedulePaint() { |
948 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); | 948 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); |
949 } | 949 } |
950 | 950 |
951 void Window::Paint(gfx::Canvas* canvas) { | 951 void Window::Paint(gfx::Canvas* canvas) { |
952 if (delegate_) | 952 if (delegate_) |
953 delegate_->OnPaint(canvas); | 953 delegate_->OnPaint(canvas); |
954 PaintLayerlessChildren(canvas); | 954 PaintLayerlessChildren(canvas); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 return delegate_ ? this : NULL; | 1023 return delegate_ ? this : NULL; |
1024 } | 1024 } |
1025 | 1025 |
1026 void Window::RemoveChildImpl(Window* child, Window* new_parent) { | 1026 void Window::RemoveChildImpl(Window* child, Window* new_parent) { |
1027 if (layout_manager_) | 1027 if (layout_manager_) |
1028 layout_manager_->OnWillRemoveWindowFromLayout(child); | 1028 layout_manager_->OnWillRemoveWindowFromLayout(child); |
1029 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); | 1029 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); |
1030 Window* root_window = child->GetRootWindow(); | 1030 Window* root_window = child->GetRootWindow(); |
1031 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL; | 1031 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL; |
1032 if (root_window && root_window != new_root_window) { | 1032 if (root_window && root_window != new_root_window) { |
1033 root_window->GetDispatcher()->OnWindowRemovedFromRootWindow( | 1033 root_window->GetHost()->dispatcher()->OnWindowRemovedFromRootWindow( |
1034 child, new_root_window); | 1034 child, new_root_window); |
1035 child->NotifyRemovingFromRootWindow(); | 1035 child->NotifyRemovingFromRootWindow(); |
1036 } | 1036 } |
1037 | 1037 |
1038 gfx::Vector2d offset; | 1038 gfx::Vector2d offset; |
1039 GetAncestorWithLayer(&offset); | 1039 GetAncestorWithLayer(&offset); |
1040 child->UnparentLayers(!layer_, offset); | 1040 child->UnparentLayers(!layer_, offset); |
1041 child->parent_ = NULL; | 1041 child->parent_ = NULL; |
1042 Windows::iterator i = std::find(children_.begin(), children_.end(), child); | 1042 Windows::iterator i = std::find(children_.begin(), children_.end(), child); |
1043 DCHECK(i != children_.end()); | 1043 DCHECK(i != children_.end()); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 } | 1337 } |
1338 } | 1338 } |
1339 | 1339 |
1340 if (layout_manager_) | 1340 if (layout_manager_) |
1341 layout_manager_->OnWindowResized(); | 1341 layout_manager_->OnWindowResized(); |
1342 if (delegate_) | 1342 if (delegate_) |
1343 delegate_->OnBoundsChanged(old_bounds, bounds()); | 1343 delegate_->OnBoundsChanged(old_bounds, bounds()); |
1344 FOR_EACH_OBSERVER(WindowObserver, | 1344 FOR_EACH_OBSERVER(WindowObserver, |
1345 observers_, | 1345 observers_, |
1346 OnWindowBoundsChanged(this, old_bounds, bounds())); | 1346 OnWindowBoundsChanged(this, old_bounds, bounds())); |
1347 WindowEventDispatcher* dispatcher = GetDispatcher(); | 1347 WindowTreeHost* host = GetHost(); |
1348 if (dispatcher) | 1348 if (host) |
1349 dispatcher->OnWindowBoundsChanged(this, contained_mouse); | 1349 host->dispatcher()->OnWindowBoundsChanged(this, contained_mouse); |
1350 } | 1350 } |
1351 | 1351 |
1352 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 1352 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
1353 Paint(canvas); | 1353 Paint(canvas); |
1354 } | 1354 } |
1355 | 1355 |
1356 base::Closure Window::PrepareForLayerBoundsChange() { | 1356 base::Closure Window::PrepareForLayerBoundsChange() { |
1357 return base::Bind(&Window::OnWindowBoundsChanged, base::Unretained(this), | 1357 return base::Bind(&Window::OnWindowBoundsChanged, base::Unretained(this), |
1358 bounds(), ContainsMouse()); | 1358 bounds(), ContainsMouse()); |
1359 } | 1359 } |
(...skipping 18 matching lines...) Expand all Loading... |
1378 if (!parent_) | 1378 if (!parent_) |
1379 return true; | 1379 return true; |
1380 | 1380 |
1381 // For located events (i.e. mouse, touch etc.), an assumption is made that | 1381 // For located events (i.e. mouse, touch etc.), an assumption is made that |
1382 // windows that don't have a delegate cannot process the event (see more in | 1382 // windows that don't have a delegate cannot process the event (see more in |
1383 // GetWindowForPoint()). This assumption is not made for key events. | 1383 // GetWindowForPoint()). This assumption is not made for key events. |
1384 return event.IsKeyEvent() || delegate_; | 1384 return event.IsKeyEvent() || delegate_; |
1385 } | 1385 } |
1386 | 1386 |
1387 ui::EventTarget* Window::GetParentTarget() { | 1387 ui::EventTarget* Window::GetParentTarget() { |
1388 if (dispatcher_) { | 1388 if (IsRootWindow()) { |
1389 return client::GetEventClient(this) ? | 1389 return client::GetEventClient(this) ? |
1390 client::GetEventClient(this)->GetToplevelEventTarget() : | 1390 client::GetEventClient(this)->GetToplevelEventTarget() : |
1391 Env::GetInstance(); | 1391 Env::GetInstance(); |
1392 } | 1392 } |
1393 return parent_; | 1393 return parent_; |
1394 } | 1394 } |
1395 | 1395 |
1396 scoped_ptr<ui::EventTargetIterator> Window::GetChildIterator() const { | 1396 scoped_ptr<ui::EventTargetIterator> Window::GetChildIterator() const { |
1397 return scoped_ptr<ui::EventTargetIterator>( | 1397 return scoped_ptr<ui::EventTargetIterator>( |
1398 new ui::EventTargetIteratorImpl<Window>(children())); | 1398 new ui::EventTargetIteratorImpl<Window>(children())); |
(...skipping 20 matching lines...) Expand all Loading... |
1419 if (id_ != -1) | 1419 if (id_ != -1) |
1420 layer_name += " " + base::IntToString(id_); | 1420 layer_name += " " + base::IntToString(id_); |
1421 | 1421 |
1422 layer_->set_name(layer_name); | 1422 layer_->set_name(layer_name); |
1423 #endif | 1423 #endif |
1424 } | 1424 } |
1425 | 1425 |
1426 bool Window::ContainsMouse() { | 1426 bool Window::ContainsMouse() { |
1427 bool contains_mouse = false; | 1427 bool contains_mouse = false; |
1428 if (IsVisible()) { | 1428 if (IsVisible()) { |
1429 WindowEventDispatcher* dispatcher = GetDispatcher(); | 1429 WindowTreeHost* host = GetHost(); |
1430 contains_mouse = dispatcher && | 1430 contains_mouse = host && |
1431 ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); | 1431 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); |
1432 } | 1432 } |
1433 return contains_mouse; | 1433 return contains_mouse; |
1434 } | 1434 } |
1435 | 1435 |
1436 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { | 1436 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { |
1437 for (const aura::Window* window = this; window; window = window->parent()) { | 1437 for (const aura::Window* window = this; window; window = window->parent()) { |
1438 if (window->layer_) | 1438 if (window->layer_) |
1439 return window; | 1439 return window; |
1440 if (offset) | 1440 if (offset) |
1441 *offset += window->bounds().OffsetFromOrigin(); | 1441 *offset += window->bounds().OffsetFromOrigin(); |
1442 } | 1442 } |
1443 if (offset) | 1443 if (offset) |
1444 *offset = gfx::Vector2d(); | 1444 *offset = gfx::Vector2d(); |
1445 return NULL; | 1445 return NULL; |
1446 } | 1446 } |
1447 | 1447 |
1448 } // namespace aura | 1448 } // namespace aura |
OLD | NEW |