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

Side by Side Diff: views/widget/root_view.cc

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 10 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/widget/root_view.h" 5 #include "views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2) 9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2)
10 #include <gdk/gdkx.h> 10 #include <gdk/gdkx.h>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 #ifndef NDEBUG 97 #ifndef NDEBUG
98 , 98 ,
99 is_processing_paint_(false) 99 is_processing_paint_(false)
100 #endif 100 #endif
101 { 101 {
102 } 102 }
103 103
104 RootView::~RootView() { 104 RootView::~RootView() {
105 // If we have children remove them explicitly so to make sure a remove 105 // If we have children remove them explicitly so to make sure a remove
106 // notification is sent for each one of them. 106 // notification is sent for each one of them.
107 if (!child_views_.empty()) 107 if (has_children())
108 RemoveAllChildViews(true); 108 RemoveAllChildViews(true);
109 109
110 if (pending_paint_task_) 110 if (pending_paint_task_)
111 pending_paint_task_->Cancel(); // Ensure we're not called any more. 111 pending_paint_task_->Cancel(); // Ensure we're not called any more.
112 } 112 }
113 113
114 void RootView::SetContentsView(View* contents_view) { 114 void RootView::SetContentsView(View* contents_view) {
115 DCHECK(contents_view && GetWidget()->GetNativeView()) << 115 DCHECK(contents_view && GetWidget()->GetNativeView()) <<
116 "Can't be called until after the native view is created!"; 116 "Can't be called until after the native view is created!";
117 // The ContentsView must be set up _after_ the window is created so that its 117 // The ContentsView must be set up _after_ the window is created so that its
118 // Widget pointer is valid. 118 // Widget pointer is valid.
119 SetLayoutManager(new FillLayout); 119 SetLayoutManager(new FillLayout);
120 if (GetChildViewCount() != 0) 120 if (has_children())
121 RemoveAllChildViews(true); 121 RemoveAllChildViews(true);
122 AddChildView(contents_view); 122 AddChildView(contents_view);
123 123
124 // Force a layout now, since the attached hierarchy won't be ready for the 124 // Force a layout now, since the attached hierarchy won't be ready for the
125 // containing window's bounds. Note that we call Layout directly rather than 125 // containing window's bounds. Note that we call Layout directly rather than
126 // calling the widget's size changed handler, since the RootView's bounds may 126 // calling the widget's size changed handler, since the RootView's bounds may
127 // not have changed, which will cause the Layout not to be done otherwise. 127 // not have changed, which will cause the Layout not to be done otherwise.
128 Layout(); 128 Layout();
129 } 129 }
130 130
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 325 status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
326 gesture_manager_->ProcessTouchEventForGesture(e, this, status); 326 gesture_manager_->ProcessTouchEventForGesture(e, this, status);
327 if (status == TOUCH_STATUS_END) 327 if (status == TOUCH_STATUS_END)
328 touch_pressed_handler_ = NULL; 328 touch_pressed_handler_ = NULL;
329 return status; 329 return status;
330 } 330 }
331 331
332 // Walk up the tree until we find a view that wants the touch event. 332 // Walk up the tree until we find a view that wants the touch event.
333 for (touch_pressed_handler_ = GetViewForPoint(e.location()); 333 for (touch_pressed_handler_ = GetViewForPoint(e.location());
334 touch_pressed_handler_ && (touch_pressed_handler_ != this); 334 touch_pressed_handler_ && (touch_pressed_handler_ != this);
335 touch_pressed_handler_ = touch_pressed_handler_->GetParent()) { 335 touch_pressed_handler_ = touch_pressed_handler_->parent()) {
336 if (!touch_pressed_handler_->IsEnabled()) { 336 if (!touch_pressed_handler_->IsEnabled()) {
337 // Disabled views eat events but are treated as not handled by the 337 // Disabled views eat events but are treated as not handled by the
338 // the GestureManager. 338 // the GestureManager.
339 status = TOUCH_STATUS_UNKNOWN; 339 status = TOUCH_STATUS_UNKNOWN;
340 break; 340 break;
341 } 341 }
342 342
343 // See if this view wants to handle the touch 343 // See if this view wants to handle the touch
344 TouchEvent touch_event(e, this, touch_pressed_handler_); 344 TouchEvent touch_event(e, this, touch_pressed_handler_);
345 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 345 status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event, 400 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event,
401 &drag_info); 401 &drag_info);
402 return true; 402 return true;
403 } 403 }
404 DCHECK(!explicit_mouse_handler_); 404 DCHECK(!explicit_mouse_handler_);
405 405
406 bool hit_disabled_view = false; 406 bool hit_disabled_view = false;
407 // Walk up the tree until we find a view that wants the mouse event. 407 // Walk up the tree until we find a view that wants the mouse event.
408 for (mouse_pressed_handler_ = GetViewForPoint(e.location()); 408 for (mouse_pressed_handler_ = GetViewForPoint(e.location());
409 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); 409 mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
410 mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) { 410 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) {
411 if (!mouse_pressed_handler_->IsEnabled()) { 411 if (!mouse_pressed_handler_->IsEnabled()) {
412 // Disabled views should eat events instead of propagating them upwards. 412 // Disabled views should eat events instead of propagating them upwards.
413 hit_disabled_view = true; 413 hit_disabled_view = true;
414 break; 414 break;
415 } 415 }
416 416
417 // See if this view wants to handle the mouse press. 417 // See if this view wants to handle the mouse press.
418 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); 418 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_);
419 419
420 // Remove the double-click flag if the handler is different than the 420 // Remove the double-click flag if the handler is different than the
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 540 }
541 } 541 }
542 542
543 void RootView::OnMouseMoved(const MouseEvent& e) { 543 void RootView::OnMouseMoved(const MouseEvent& e) {
544 View* v = GetViewForPoint(e.location()); 544 View* v = GetViewForPoint(e.location());
545 // Find the first enabled view, or the existing move handler, whichever comes 545 // Find the first enabled view, or the existing move handler, whichever comes
546 // first. The check for the existing handler is because if a view becomes 546 // first. The check for the existing handler is because if a view becomes
547 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED 547 // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED
548 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. 548 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
549 while (v && !v->IsEnabled() && (v != mouse_move_handler_)) 549 while (v && !v->IsEnabled() && (v != mouse_move_handler_))
550 v = v->GetParent(); 550 v = v->parent();
551 if (v && v != this) { 551 if (v && v != this) {
552 if (v != mouse_move_handler_) { 552 if (v != mouse_move_handler_) {
553 if (mouse_move_handler_ != NULL) { 553 if (mouse_move_handler_ != NULL) {
554 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0); 554 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0);
555 mouse_move_handler_->OnMouseExited(exited_event); 555 mouse_move_handler_->OnMouseExited(exited_event);
556 } 556 }
557 557
558 mouse_move_handler_ = v; 558 mouse_move_handler_ = v;
559 559
560 MouseEvent entered_event(Event::ET_MOUSE_ENTERED, 560 MouseEvent entered_event(Event::ET_MOUSE_ENTERED,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 bool consumed = false; 674 bool consumed = false;
675 675
676 View* v = GetFocusedView(); 676 View* v = GetFocusedView();
677 // Special case to handle right-click context menus triggered by the 677 // Special case to handle right-click context menus triggered by the
678 // keyboard. 678 // keyboard.
679 if (v && v->IsEnabled() && ((event.GetKeyCode() == ui::VKEY_APPS) || 679 if (v && v->IsEnabled() && ((event.GetKeyCode() == ui::VKEY_APPS) ||
680 (event.GetKeyCode() == ui::VKEY_F10 && event.IsShiftDown()))) { 680 (event.GetKeyCode() == ui::VKEY_F10 && event.IsShiftDown()))) {
681 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); 681 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false);
682 return true; 682 return true;
683 } 683 }
684 for (; v && v != this && !consumed; v = v->GetParent()) { 684 for (; v && v != this && !consumed; v = v->parent()) {
685 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? 685 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
686 v->OnKeyPressed(event) : v->OnKeyReleased(event); 686 v->OnKeyPressed(event) : v->OnKeyReleased(event);
687 } 687 }
688 688
689 if (!consumed && default_keyboard_handler_) { 689 if (!consumed && default_keyboard_handler_) {
690 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? 690 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
691 default_keyboard_handler_->OnKeyPressed(event) : 691 default_keyboard_handler_->OnKeyPressed(event) :
692 default_keyboard_handler_->OnKeyReleased(event); 692 default_keyboard_handler_->OnKeyReleased(event);
693 } 693 }
694 694
695 return consumed; 695 return consumed;
696 } 696 }
697 697
698 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { 698 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) {
699 View* v; 699 View* v;
700 bool consumed = false; 700 bool consumed = false;
701 if (GetFocusedView()) { 701 if (GetFocusedView()) {
702 for (v = GetFocusedView(); 702 for (v = GetFocusedView(); v && v != this && !consumed; v = v->parent())
703 v && v != this && !consumed; v = v->GetParent()) {
704 consumed = v->OnMouseWheel(e); 703 consumed = v->OnMouseWheel(e);
705 }
706 } 704 }
707 705
708 if (!consumed && default_keyboard_handler_) { 706 if (!consumed && default_keyboard_handler_) {
709 consumed = default_keyboard_handler_->OnMouseWheel(e); 707 consumed = default_keyboard_handler_->OnMouseWheel(e);
710 } 708 }
711 return consumed; 709 return consumed;
712 } 710 }
713 711
714 void RootView::SetDefaultKeyboardHandler(View* v) { 712 void RootView::SetDefaultKeyboardHandler(View* v) {
715 default_keyboard_handler_ = v; 713 default_keyboard_handler_ = v;
(...skipping 13 matching lines...) Expand all
729 i != view->descendants_to_notify_->end(); ++i) { 727 i != view->descendants_to_notify_->end(); ++i) {
730 (*i)->VisibleBoundsInRootChanged(); 728 (*i)->VisibleBoundsInRootChanged();
731 } 729 }
732 } 730 }
733 731
734 void RootView::RegisterViewForVisibleBoundsNotification(View* view) { 732 void RootView::RegisterViewForVisibleBoundsNotification(View* view) {
735 DCHECK(view); 733 DCHECK(view);
736 if (view->registered_for_visible_bounds_notification_) 734 if (view->registered_for_visible_bounds_notification_)
737 return; 735 return;
738 view->registered_for_visible_bounds_notification_ = true; 736 view->registered_for_visible_bounds_notification_ = true;
739 View* ancestor = view->GetParent(); 737 View* ancestor = view->parent();
740 while (ancestor) { 738 while (ancestor) {
741 ancestor->AddDescendantToNotify(view); 739 ancestor->AddDescendantToNotify(view);
742 ancestor = ancestor->GetParent(); 740 ancestor = ancestor->parent();
743 } 741 }
744 } 742 }
745 743
746 void RootView::UnregisterViewForVisibleBoundsNotification(View* view) { 744 void RootView::UnregisterViewForVisibleBoundsNotification(View* view) {
747 DCHECK(view); 745 DCHECK(view);
748 if (!view->registered_for_visible_bounds_notification_) 746 if (!view->registered_for_visible_bounds_notification_)
749 return; 747 return;
750 view->registered_for_visible_bounds_notification_ = false; 748 view->registered_for_visible_bounds_notification_ = false;
751 View* ancestor = view->GetParent(); 749 View* ancestor = view->parent();
752 while (ancestor) { 750 while (ancestor) {
753 ancestor->RemoveDescendantToNotify(view); 751 ancestor->RemoveDescendantToNotify(view);
754 ancestor = ancestor->GetParent(); 752 ancestor = ancestor->parent();
755 } 753 }
756 } 754 }
757 755
758 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { 756 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) {
759 last_mouse_event_flags_ = e.GetFlags(); 757 last_mouse_event_flags_ = e.GetFlags();
760 last_mouse_event_x_ = e.x(); 758 last_mouse_event_x_ = e.x();
761 last_mouse_event_y_ = e.y(); 759 last_mouse_event_y_ = e.y();
762 } 760 }
763 761
764 std::string RootView::GetClassName() const { 762 std::string RootView::GetClassName() const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (!TouchFactory::GetInstance()->is_cursor_visible()) { 805 if (!TouchFactory::GetInstance()->is_cursor_visible()) {
808 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); 806 cursor = gfx::GetCursor(GDK_BLANK_CURSOR);
809 } 807 }
810 #endif 808 #endif
811 809
812 gdk_window_set_cursor(native_view->window, cursor); 810 gdk_window_set_cursor(native_view->window, cursor);
813 #endif 811 #endif
814 } 812 }
815 813
816 } // namespace views 814 } // namespace views
OLDNEW
« views/view.cc ('K') | « views/widget/drop_helper.cc ('k') | views/window/client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698