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

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
« no previous file with comments | « views/widget/root_view.h ('k') | views/window/client_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 return invalid_rect_.Intersect(GetLocalBounds()); 246 return invalid_rect_.Intersect(GetLocalBounds());
247 } 247 }
248 248
249 ///////////////////////////////////////////////////////////////////////////// 249 /////////////////////////////////////////////////////////////////////////////
250 // 250 //
251 // RootView - tree 251 // RootView - tree
252 // 252 //
253 ///////////////////////////////////////////////////////////////////////////// 253 /////////////////////////////////////////////////////////////////////////////
254 254
255 Widget* RootView::GetWidget() const { 255 const Widget* RootView::GetWidget() const {
256 return widget_; 256 return widget_;
257 } 257 }
258 258
259 Widget* RootView::GetWidget() {
260 return const_cast<Widget*>(const_cast<const RootView*>(this)->GetWidget());
261 }
262
259 void RootView::NotifyThemeChanged() { 263 void RootView::NotifyThemeChanged() {
260 View::PropagateThemeChanged(); 264 View::PropagateThemeChanged();
261 } 265 }
262 266
263 void RootView::NotifyLocaleChanged() { 267 void RootView::NotifyLocaleChanged() {
264 View::PropagateLocaleChanged(); 268 View::PropagateLocaleChanged();
265 } 269 }
266 270
267 ///////////////////////////////////////////////////////////////////////////// 271 /////////////////////////////////////////////////////////////////////////////
268 // 272 //
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 329 status = touch_pressed_handler_->ProcessTouchEvent(touch_event);
326 gesture_manager_->ProcessTouchEventForGesture(e, this, status); 330 gesture_manager_->ProcessTouchEventForGesture(e, this, status);
327 if (status == TOUCH_STATUS_END) 331 if (status == TOUCH_STATUS_END)
328 touch_pressed_handler_ = NULL; 332 touch_pressed_handler_ = NULL;
329 return status; 333 return status;
330 } 334 }
331 335
332 // Walk up the tree until we find a view that wants the touch event. 336 // Walk up the tree until we find a view that wants the touch event.
333 for (touch_pressed_handler_ = GetViewForPoint(e.location()); 337 for (touch_pressed_handler_ = GetViewForPoint(e.location());
334 touch_pressed_handler_ && (touch_pressed_handler_ != this); 338 touch_pressed_handler_ && (touch_pressed_handler_ != this);
335 touch_pressed_handler_ = touch_pressed_handler_->GetParent()) { 339 touch_pressed_handler_ = touch_pressed_handler_->parent()) {
336 if (!touch_pressed_handler_->IsEnabled()) { 340 if (!touch_pressed_handler_->IsEnabled()) {
337 // Disabled views eat events but are treated as not handled by the 341 // Disabled views eat events but are treated as not handled by the
338 // the GestureManager. 342 // the GestureManager.
339 status = TOUCH_STATUS_UNKNOWN; 343 status = TOUCH_STATUS_UNKNOWN;
340 break; 344 break;
341 } 345 }
342 346
343 // See if this view wants to handle the touch 347 // See if this view wants to handle the touch
344 TouchEvent touch_event(e, this, touch_pressed_handler_); 348 TouchEvent touch_event(e, this, touch_pressed_handler_);
345 status = touch_pressed_handler_->ProcessTouchEvent(touch_event); 349 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, 404 mouse_pressed_handler_->ProcessMousePressed(mouse_pressed_event,
401 &drag_info); 405 &drag_info);
402 return true; 406 return true;
403 } 407 }
404 DCHECK(!explicit_mouse_handler_); 408 DCHECK(!explicit_mouse_handler_);
405 409
406 bool hit_disabled_view = false; 410 bool hit_disabled_view = false;
407 // Walk up the tree until we find a view that wants the mouse event. 411 // Walk up the tree until we find a view that wants the mouse event.
408 for (mouse_pressed_handler_ = GetViewForPoint(e.location()); 412 for (mouse_pressed_handler_ = GetViewForPoint(e.location());
409 mouse_pressed_handler_ && (mouse_pressed_handler_ != this); 413 mouse_pressed_handler_ && (mouse_pressed_handler_ != this);
410 mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) { 414 mouse_pressed_handler_ = mouse_pressed_handler_->parent()) {
411 if (!mouse_pressed_handler_->IsEnabled()) { 415 if (!mouse_pressed_handler_->IsEnabled()) {
412 // Disabled views should eat events instead of propagating them upwards. 416 // Disabled views should eat events instead of propagating them upwards.
413 hit_disabled_view = true; 417 hit_disabled_view = true;
414 break; 418 break;
415 } 419 }
416 420
417 // See if this view wants to handle the mouse press. 421 // See if this view wants to handle the mouse press.
418 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_); 422 MouseEvent mouse_pressed_event(e, this, mouse_pressed_handler_);
419 423
420 // Remove the double-click flag if the handler is different than the 424 // 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 } 544 }
541 } 545 }
542 546
543 void RootView::OnMouseMoved(const MouseEvent& e) { 547 void RootView::OnMouseMoved(const MouseEvent& e) {
544 View* v = GetViewForPoint(e.location()); 548 View* v = GetViewForPoint(e.location());
545 // Find the first enabled view, or the existing move handler, whichever comes 549 // 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 550 // 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 551 // 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. 552 // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet.
549 while (v && !v->IsEnabled() && (v != mouse_move_handler_)) 553 while (v && !v->IsEnabled() && (v != mouse_move_handler_))
550 v = v->GetParent(); 554 v = v->parent();
551 if (v && v != this) { 555 if (v && v != this) {
552 if (v != mouse_move_handler_) { 556 if (v != mouse_move_handler_) {
553 if (mouse_move_handler_ != NULL) { 557 if (mouse_move_handler_ != NULL) {
554 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0); 558 MouseEvent exited_event(Event::ET_MOUSE_EXITED, 0, 0, 0);
555 mouse_move_handler_->OnMouseExited(exited_event); 559 mouse_move_handler_->OnMouseExited(exited_event);
556 } 560 }
557 561
558 mouse_move_handler_ = v; 562 mouse_move_handler_ = v;
559 563
560 MouseEvent entered_event(Event::ET_MOUSE_ENTERED, 564 MouseEvent entered_event(Event::ET_MOUSE_ENTERED,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 bool consumed = false; 678 bool consumed = false;
675 679
676 View* v = GetFocusedView(); 680 View* v = GetFocusedView();
677 // Special case to handle right-click context menus triggered by the 681 // Special case to handle right-click context menus triggered by the
678 // keyboard. 682 // keyboard.
679 if (v && v->IsEnabled() && ((event.GetKeyCode() == ui::VKEY_APPS) || 683 if (v && v->IsEnabled() && ((event.GetKeyCode() == ui::VKEY_APPS) ||
680 (event.GetKeyCode() == ui::VKEY_F10 && event.IsShiftDown()))) { 684 (event.GetKeyCode() == ui::VKEY_F10 && event.IsShiftDown()))) {
681 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); 685 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false);
682 return true; 686 return true;
683 } 687 }
684 for (; v && v != this && !consumed; v = v->GetParent()) { 688 for (; v && v != this && !consumed; v = v->parent()) {
685 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? 689 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
686 v->OnKeyPressed(event) : v->OnKeyReleased(event); 690 v->OnKeyPressed(event) : v->OnKeyReleased(event);
687 } 691 }
688 692
689 if (!consumed && default_keyboard_handler_) { 693 if (!consumed && default_keyboard_handler_) {
690 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? 694 consumed = (event.GetType() == Event::ET_KEY_PRESSED) ?
691 default_keyboard_handler_->OnKeyPressed(event) : 695 default_keyboard_handler_->OnKeyPressed(event) :
692 default_keyboard_handler_->OnKeyReleased(event); 696 default_keyboard_handler_->OnKeyReleased(event);
693 } 697 }
694 698
695 return consumed; 699 return consumed;
696 } 700 }
697 701
698 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { 702 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) {
699 View* v; 703 View* v;
700 bool consumed = false; 704 bool consumed = false;
701 if (GetFocusedView()) { 705 if (GetFocusedView()) {
702 for (v = GetFocusedView(); 706 for (v = GetFocusedView(); v && v != this && !consumed; v = v->parent())
703 v && v != this && !consumed; v = v->GetParent()) {
704 consumed = v->OnMouseWheel(e); 707 consumed = v->OnMouseWheel(e);
705 }
706 } 708 }
707 709
708 if (!consumed && default_keyboard_handler_) { 710 if (!consumed && default_keyboard_handler_) {
709 consumed = default_keyboard_handler_->OnMouseWheel(e); 711 consumed = default_keyboard_handler_->OnMouseWheel(e);
710 } 712 }
711 return consumed; 713 return consumed;
712 } 714 }
713 715
714 void RootView::SetDefaultKeyboardHandler(View* v) { 716 void RootView::SetDefaultKeyboardHandler(View* v) {
715 default_keyboard_handler_ = v; 717 default_keyboard_handler_ = v;
(...skipping 13 matching lines...) Expand all
729 i != view->descendants_to_notify_->end(); ++i) { 731 i != view->descendants_to_notify_->end(); ++i) {
730 (*i)->VisibleBoundsInRootChanged(); 732 (*i)->VisibleBoundsInRootChanged();
731 } 733 }
732 } 734 }
733 735
734 void RootView::RegisterViewForVisibleBoundsNotification(View* view) { 736 void RootView::RegisterViewForVisibleBoundsNotification(View* view) {
735 DCHECK(view); 737 DCHECK(view);
736 if (view->registered_for_visible_bounds_notification_) 738 if (view->registered_for_visible_bounds_notification_)
737 return; 739 return;
738 view->registered_for_visible_bounds_notification_ = true; 740 view->registered_for_visible_bounds_notification_ = true;
739 View* ancestor = view->GetParent(); 741 View* ancestor = view->parent();
740 while (ancestor) { 742 while (ancestor) {
741 ancestor->AddDescendantToNotify(view); 743 ancestor->AddDescendantToNotify(view);
742 ancestor = ancestor->GetParent(); 744 ancestor = ancestor->parent();
743 } 745 }
744 } 746 }
745 747
746 void RootView::UnregisterViewForVisibleBoundsNotification(View* view) { 748 void RootView::UnregisterViewForVisibleBoundsNotification(View* view) {
747 DCHECK(view); 749 DCHECK(view);
748 if (!view->registered_for_visible_bounds_notification_) 750 if (!view->registered_for_visible_bounds_notification_)
749 return; 751 return;
750 view->registered_for_visible_bounds_notification_ = false; 752 view->registered_for_visible_bounds_notification_ = false;
751 View* ancestor = view->GetParent(); 753 View* ancestor = view->parent();
752 while (ancestor) { 754 while (ancestor) {
753 ancestor->RemoveDescendantToNotify(view); 755 ancestor->RemoveDescendantToNotify(view);
754 ancestor = ancestor->GetParent(); 756 ancestor = ancestor->parent();
755 } 757 }
756 } 758 }
757 759
758 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { 760 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) {
759 last_mouse_event_flags_ = e.GetFlags(); 761 last_mouse_event_flags_ = e.GetFlags();
760 last_mouse_event_x_ = e.x(); 762 last_mouse_event_x_ = e.x();
761 last_mouse_event_y_ = e.y(); 763 last_mouse_event_y_ = e.y();
762 } 764 }
763 765
764 std::string RootView::GetClassName() const { 766 std::string RootView::GetClassName() const {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (!TouchFactory::GetInstance()->is_cursor_visible()) { 809 if (!TouchFactory::GetInstance()->is_cursor_visible()) {
808 cursor = gfx::GetCursor(GDK_BLANK_CURSOR); 810 cursor = gfx::GetCursor(GDK_BLANK_CURSOR);
809 } 811 }
810 #endif 812 #endif
811 813
812 gdk_window_set_cursor(native_view->window, cursor); 814 gdk_window_set_cursor(native_view->window, cursor);
813 #endif 815 #endif
814 } 816 }
815 817
816 } // namespace views 818 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/root_view.h ('k') | views/window/client_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698