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

Side by Side Diff: views/view.cc

Issue 6507028: Remove usages of RootView from View by moving relevant RootView API methods t... (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/view.h ('k') | views/widget/native_widget.h » ('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/view.h" 5 #include "views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) { 529 void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) {
530 if (group_ == group_id) 530 if (group_ == group_id)
531 out->push_back(this); 531 out->push_back(this);
532 532
533 for (int i = 0, count = child_count(); i < count; ++i) 533 for (int i = 0, count = child_count(); i < count; ++i)
534 GetChildViewAt(i)->GetViewsWithGroup(group_id, out); 534 GetChildViewAt(i)->GetViewsWithGroup(group_id, out);
535 } 535 }
536 536
537 View* View::GetSelectedViewForGroup(int group_id) { 537 View* View::GetSelectedViewForGroup(int group_id) {
538 std::vector<View*> views; 538 std::vector<View*> views;
539 GetRootView()->GetViewsWithGroup(group_id, &views); 539 GetWidget()->GetRootView()->GetViewsWithGroup(group_id, &views);
540 if (views.size() > 0) 540 if (views.size() > 0)
541 return views[0]; 541 return views[0];
542 else 542 else
543 return NULL; 543 return NULL;
544 } 544 }
545 545
546 // Coordinate conversion ------------------------------------------------------- 546 // Coordinate conversion -------------------------------------------------------
547 547
548 // static 548 // static
549 void View::ConvertPointToView(const View* src, 549 void View::ConvertPointToView(const View* src,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 789 }
790 790
791 size_t index = iter - accelerators_->begin(); 791 size_t index = iter - accelerators_->begin();
792 accelerators_->erase(iter); 792 accelerators_->erase(iter);
793 if (index >= registered_accelerator_count_) { 793 if (index >= registered_accelerator_count_) {
794 // The accelerator is not registered to FocusManager. 794 // The accelerator is not registered to FocusManager.
795 return; 795 return;
796 } 796 }
797 --registered_accelerator_count_; 797 --registered_accelerator_count_;
798 798
799 RootView* root_view = GetRootView(); 799 // Providing we are attached to a Widget and registered with a focus manager,
800 if (!root_view) { 800 // we should de-register from that focus manager now.
801 // We are not part of a view hierarchy, so there is nothing to do as we 801 if (GetWidget() && accelerator_focus_manager_)
802 // removed ourselves from accelerators_, we won't be registered when added
803 // to one.
804 return;
805 }
806
807 // If accelerator_focus_manager_ is NULL then we did not registered
808 // accelerators so there is nothing to unregister.
809 if (accelerator_focus_manager_) {
810 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); 802 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this);
811 }
812 } 803 }
813 804
814 void View::ResetAccelerators() { 805 void View::ResetAccelerators() {
815 if (accelerators_.get()) 806 if (accelerators_.get())
816 UnregisterAccelerators(false); 807 UnregisterAccelerators(false);
817 } 808 }
818 809
819 // Focus ----------------------------------------------------------------------- 810 // Focus -----------------------------------------------------------------------
820 811
821 bool View::HasFocus() { 812 bool View::HasFocus() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 return (focusable_ || accessibility_focusable_) && IsEnabled() && 845 return (focusable_ || accessibility_focusable_) && IsEnabled() &&
855 IsVisibleInRootView(); 846 IsVisibleInRootView();
856 } 847 }
857 848
858 FocusManager* View::GetFocusManager() { 849 FocusManager* View::GetFocusManager() {
859 Widget* widget = GetWidget(); 850 Widget* widget = GetWidget();
860 return widget ? widget->GetFocusManager() : NULL; 851 return widget ? widget->GetFocusManager() : NULL;
861 } 852 }
862 853
863 void View::RequestFocus() { 854 void View::RequestFocus() {
864 RootView* rv = GetRootView(); 855 FocusManager* focus_manager = GetFocusManager();
865 if (rv && IsFocusableInRootView()) 856 if (focus_manager && IsFocusableInRootView())
866 rv->FocusView(this); 857 focus_manager->SetFocusedView(this);
867 } 858 }
868 859
869 void View::WillGainFocus() { 860 void View::WillGainFocus() {
870 } 861 }
871 862
872 void View::DidGainFocus() { 863 void View::DidGainFocus() {
873 } 864 }
874 865
875 void View::WillLoseFocus() { 866 void View::WillLoseFocus() {
876 } 867 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 return ui::DragDropTypes::DRAG_NONE; 921 return ui::DragDropTypes::DRAG_NONE;
931 } 922 }
932 923
933 void View::OnDragExited() { 924 void View::OnDragExited() {
934 } 925 }
935 926
936 int View::OnPerformDrop(const DropTargetEvent& event) { 927 int View::OnPerformDrop(const DropTargetEvent& event) {
937 return ui::DragDropTypes::DRAG_NONE; 928 return ui::DragDropTypes::DRAG_NONE;
938 } 929 }
939 930
931 void View::OnDragDone() {
932 }
933
940 // static 934 // static
941 bool View::ExceededDragThreshold(int delta_x, int delta_y) { 935 bool View::ExceededDragThreshold(int delta_x, int delta_y) {
942 return (abs(delta_x) > GetHorizontalDragThreshold() || 936 return (abs(delta_x) > GetHorizontalDragThreshold() ||
943 abs(delta_y) > GetVerticalDragThreshold()); 937 abs(delta_y) > GetVerticalDragThreshold());
944 } 938 }
945 939
946 // Accessibility --------------------------------------------------------------- 940 // Accessibility ---------------------------------------------------------------
947 941
948 void View::NotifyAccessibilityEvent(AccessibilityTypes::Event event_type) { 942 void View::NotifyAccessibilityEvent(AccessibilityTypes::Event event_type) {
949 NotifyAccessibilityEvent(event_type, true); 943 NotifyAccessibilityEvent(event_type, true);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 return drag_controller_ ? 1117 return drag_controller_ ?
1124 drag_controller_->GetDragOperations(this, press_pt) : 1118 drag_controller_->GetDragOperations(this, press_pt) :
1125 ui::DragDropTypes::DRAG_NONE; 1119 ui::DragDropTypes::DRAG_NONE;
1126 } 1120 }
1127 1121
1128 void View::WriteDragData(const gfx::Point& press_pt, OSExchangeData* data) { 1122 void View::WriteDragData(const gfx::Point& press_pt, OSExchangeData* data) {
1129 DCHECK(drag_controller_); 1123 DCHECK(drag_controller_);
1130 drag_controller_->WriteDragData(this, press_pt, data); 1124 drag_controller_->WriteDragData(this, press_pt, data);
1131 } 1125 }
1132 1126
1133 void View::OnDragDone() {
1134 }
1135
1136 bool View::InDrag() { 1127 bool View::InDrag() {
1137 RootView* root_view = GetRootView(); 1128 Widget* widget = GetWidget();
1138 return root_view ? (root_view->GetDragView() == this) : false; 1129 return widget ? widget->GetDraggedView() == this : false;
1139 } 1130 }
1140 1131
1141 //////////////////////////////////////////////////////////////////////////////// 1132 ////////////////////////////////////////////////////////////////////////////////
1142 // View, private: 1133 // View, private:
1143 1134
1144 // DropInfo -------------------------------------------------------------------- 1135 // DropInfo --------------------------------------------------------------------
1145 1136
1146 void View::DragInfo::Reset() { 1137 void View::DragInfo::Reset() {
1147 possible_drag = false; 1138 possible_drag = false;
1148 start_pt = gfx::Point(); 1139 start_pt = gfx::Point();
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 1445
1455 // Accelerators ---------------------------------------------------------------- 1446 // Accelerators ----------------------------------------------------------------
1456 1447
1457 void View::RegisterPendingAccelerators() { 1448 void View::RegisterPendingAccelerators() {
1458 if (!accelerators_.get() || 1449 if (!accelerators_.get() ||
1459 registered_accelerator_count_ == accelerators_->size()) { 1450 registered_accelerator_count_ == accelerators_->size()) {
1460 // No accelerators are waiting for registration. 1451 // No accelerators are waiting for registration.
1461 return; 1452 return;
1462 } 1453 }
1463 1454
1464 RootView* root_view = GetRootView(); 1455 if (!GetWidget()) {
1465 if (!root_view) { 1456 // The view is not yet attached to a widget, defer registration until then.
1466 // We are not yet part of a view hierarchy, we'll register ourselves once
1467 // added to one.
1468 return; 1457 return;
1469 } 1458 }
1470 1459
1471 accelerator_focus_manager_ = GetFocusManager(); 1460 accelerator_focus_manager_ = GetFocusManager();
1472 if (!accelerator_focus_manager_) { 1461 if (!accelerator_focus_manager_) {
1473 // Some crash reports seem to show that we may get cases where we have no 1462 // Some crash reports seem to show that we may get cases where we have no
1474 // focus manager (see bug #1291225). This should never be the case, just 1463 // focus manager (see bug #1291225). This should never be the case, just
1475 // making sure we don't crash. 1464 // making sure we don't crash.
1476 1465
1477 // TODO(jcampan): This fails for a view under WidgetGtk with TYPE_CHILD. 1466 // TODO(jcampan): This fails for a view under WidgetGtk with TYPE_CHILD.
(...skipping 12 matching lines...) Expand all
1490 iter != accelerators_->end(); ++iter) { 1479 iter != accelerators_->end(); ++iter) {
1491 accelerator_focus_manager_->RegisterAccelerator(*iter, this); 1480 accelerator_focus_manager_->RegisterAccelerator(*iter, this);
1492 } 1481 }
1493 registered_accelerator_count_ = accelerators_->size(); 1482 registered_accelerator_count_ = accelerators_->size();
1494 } 1483 }
1495 1484
1496 void View::UnregisterAccelerators(bool leave_data_intact) { 1485 void View::UnregisterAccelerators(bool leave_data_intact) {
1497 if (!accelerators_.get()) 1486 if (!accelerators_.get())
1498 return; 1487 return;
1499 1488
1500 RootView* root_view = GetRootView(); 1489 if (GetWidget()) {
1501 if (root_view) {
1502 if (accelerator_focus_manager_) { 1490 if (accelerator_focus_manager_) {
1503 // We may not have a FocusManager if the window containing us is being 1491 // We may not have a FocusManager if the window containing us is being
1504 // closed, in which case the FocusManager is being deleted so there is 1492 // closed, in which case the FocusManager is being deleted so there is
1505 // nothing to unregister. 1493 // nothing to unregister.
1506 accelerator_focus_manager_->UnregisterAccelerators(this); 1494 accelerator_focus_manager_->UnregisterAccelerators(this);
1507 accelerator_focus_manager_ = NULL; 1495 accelerator_focus_manager_ = NULL;
1508 } 1496 }
1509 if (!leave_data_intact) { 1497 if (!leave_data_intact) {
1510 accelerators_->clear(); 1498 accelerators_->clear();
1511 accelerators_.reset(); 1499 accelerators_.reset();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 void View::DoDrag(const MouseEvent& e, const gfx::Point& press_pt) { 1574 void View::DoDrag(const MouseEvent& e, const gfx::Point& press_pt) {
1587 int drag_operations = GetDragOperations(press_pt); 1575 int drag_operations = GetDragOperations(press_pt);
1588 if (drag_operations == ui::DragDropTypes::DRAG_NONE) 1576 if (drag_operations == ui::DragDropTypes::DRAG_NONE)
1589 return; 1577 return;
1590 1578
1591 OSExchangeData data; 1579 OSExchangeData data;
1592 WriteDragData(press_pt, &data); 1580 WriteDragData(press_pt, &data);
1593 1581
1594 // Message the RootView to do the drag and drop. That way if we're removed 1582 // Message the RootView to do the drag and drop. That way if we're removed
1595 // the RootView can detect it and avoid calling us back. 1583 // the RootView can detect it and avoid calling us back.
1596 RootView* root_view = GetRootView(); 1584 GetWidget()->StartDragForViewFromMouseEvent(this, data, drag_operations);
1597 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations);
1598 } 1585 }
1599 1586
1600 } // namespace views 1587 } // namespace views
OLDNEW
« no previous file with comments | « views/view.h ('k') | views/widget/native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698