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 #ifndef UI_VIEWS_VIEW_H_ | 5 #ifndef UI_VIEWS_VIEW_H_ |
6 #define UI_VIEWS_VIEW_H_ | 6 #define UI_VIEWS_VIEW_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 // | 109 // |
110 ///////////////////////////////////////////////////////////////////////////// | 110 ///////////////////////////////////////////////////////////////////////////// |
111 class VIEWS_EXPORT View : public ui::LayerDelegate, | 111 class VIEWS_EXPORT View : public ui::LayerDelegate, |
112 public ui::LayerOwner, | 112 public ui::LayerOwner, |
113 public ui::AcceleratorTarget, | 113 public ui::AcceleratorTarget, |
114 public ui::EventTarget, | 114 public ui::EventTarget, |
115 public ui::EventHandler { | 115 public ui::EventHandler { |
116 public: | 116 public: |
117 typedef std::vector<View*> Views; | 117 typedef std::vector<View*> Views; |
118 | 118 |
119 enum class FocusBehavior { | |
120 // Use when the View is never focusable. Default. | |
121 NEVER, | |
122 | |
123 // Use when the View is to be focusable both in regular and accessibility | |
124 // mode. | |
125 ALWAYS, | |
126 | |
127 // Use when the View is focusable only during accessibility mode. | |
128 ACCESSIBLE_ONLY, | |
129 }; | |
130 | |
119 struct ViewHierarchyChangedDetails { | 131 struct ViewHierarchyChangedDetails { |
120 ViewHierarchyChangedDetails() | 132 ViewHierarchyChangedDetails() |
121 : is_add(false), | 133 : is_add(false), |
122 parent(NULL), | 134 parent(NULL), |
123 child(NULL), | 135 child(NULL), |
124 move_view(NULL) {} | 136 move_view(NULL) {} |
125 | 137 |
126 ViewHierarchyChangedDetails(bool is_add, | 138 ViewHierarchyChangedDetails(bool is_add, |
127 View* parent, | 139 View* parent, |
128 View* child, | 140 View* child, |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 // Returns the view that should be selected next when pressing Shift-Tab. | 772 // Returns the view that should be selected next when pressing Shift-Tab. |
761 View* GetPreviousFocusableView(); | 773 View* GetPreviousFocusableView(); |
762 | 774 |
763 // Sets the component that should be selected next when pressing Tab, and | 775 // Sets the component that should be selected next when pressing Tab, and |
764 // makes the current view the precedent view of the specified one. | 776 // makes the current view the precedent view of the specified one. |
765 // Note that by default views are linked in the order they have been added to | 777 // Note that by default views are linked in the order they have been added to |
766 // their container. Use this method if you want to modify the order. | 778 // their container. Use this method if you want to modify the order. |
767 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. | 779 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. |
768 void SetNextFocusableView(View* view); | 780 void SetNextFocusableView(View* view); |
769 | 781 |
770 // Sets whether this view is capable of taking focus. It will clear focus if | 782 // Sets |focus_behavior| and advances focus if necessary. |
771 // the focused view is set to be non-focusable. | 783 void SetFocusBehavior(FocusBehavior focus_behavior); |
772 // Note that this is false by default so that a view used as a container does | |
773 // not get the focus. | |
774 void SetFocusable(bool focusable); | |
775 | 784 |
776 // Returns true if this view is |focusable_|, |enabled_| and drawn. | 785 // Returns true if this view is focusable, |enabled_| and drawn. |
777 bool IsFocusable() const; | 786 bool IsFocusable() const; |
778 | 787 |
779 // Return whether this view is focusable when the user requires full keyboard | 788 // Return whether this view is focusable when the user requires full keyboard |
780 // access, even though it may not be normally focusable. | 789 // access, even though it may not be normally focusable. |
781 bool IsAccessibilityFocusable() const; | 790 bool IsAccessibilityFocusable() const; |
782 | 791 |
783 // Set whether this view can be made focusable if the user requires | |
784 // full keyboard access, even though it's not normally focusable. It will | |
785 // clear focus if the focused view is set to be non-focusable. | |
786 // Note that this is false by default. | |
787 void SetAccessibilityFocusable(bool accessibility_focusable); | |
788 | |
789 // Convenience method to retrieve the FocusManager associated with the | 792 // Convenience method to retrieve the FocusManager associated with the |
790 // Widget that contains this view. This can return NULL if this view is not | 793 // Widget that contains this view. This can return NULL if this view is not |
791 // part of a view hierarchy with a Widget. | 794 // part of a view hierarchy with a Widget. |
792 virtual FocusManager* GetFocusManager(); | 795 virtual FocusManager* GetFocusManager(); |
793 virtual const FocusManager* GetFocusManager() const; | 796 virtual const FocusManager* GetFocusManager() const; |
794 | 797 |
795 // Request keyboard focus. The receiving view will become the focused view. | 798 // Request keyboard focus. The receiving view will become the focused view. |
796 virtual void RequestFocus(); | 799 virtual void RequestFocus(); |
797 | 800 |
798 // Invoked when a view is about to be requested for focus due to the focus | 801 // Invoked when a view is about to be requested for focus due to the focus |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 // with an associated view. Widget::ReorderNativeViews() may reorder layers | 1137 // with an associated view. Widget::ReorderNativeViews() may reorder layers |
1135 // below layers owned by a view. | 1138 // below layers owned by a view. |
1136 virtual void ReorderChildLayers(ui::Layer* parent_layer); | 1139 virtual void ReorderChildLayers(ui::Layer* parent_layer); |
1137 | 1140 |
1138 // Input --------------------------------------------------------------------- | 1141 // Input --------------------------------------------------------------------- |
1139 | 1142 |
1140 virtual DragInfo* GetDragInfo(); | 1143 virtual DragInfo* GetDragInfo(); |
1141 | 1144 |
1142 // Focus --------------------------------------------------------------------- | 1145 // Focus --------------------------------------------------------------------- |
1143 | 1146 |
1144 // Returns last value passed to SetFocusable(). Use IsFocusable() to determine | 1147 // Returns true if ALWAYS is the last set focus behavior. Use IsFocusable() to |
1145 // if a view can take focus right now. | 1148 // determine if a view can take focus right now. |
1146 bool focusable() const { return focusable_; } | 1149 bool focusable() const { return focus_behavior_ == FocusBehavior::ALWAYS; } |
sky
2016/04/21 16:44:17
This function is mildly confusing now. Can you rem
karandeepb
2016/04/22 08:38:29
This would involve some investigation on my part s
| |
1147 | 1150 |
1148 // Override to be notified when focus has changed either to or from this View. | 1151 // Override to be notified when focus has changed either to or from this View. |
1149 virtual void OnFocus(); | 1152 virtual void OnFocus(); |
1150 virtual void OnBlur(); | 1153 virtual void OnBlur(); |
1151 | 1154 |
1152 // Handle view focus/blur events for this view. | 1155 // Handle view focus/blur events for this view. |
1153 void Focus(); | 1156 void Focus(); |
1154 void Blur(); | 1157 void Blur(); |
1155 | 1158 |
1156 // System events ------------------------------------------------------------- | 1159 // System events ------------------------------------------------------------- |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1537 size_t registered_accelerator_count_; | 1540 size_t registered_accelerator_count_; |
1538 | 1541 |
1539 // Focus --------------------------------------------------------------------- | 1542 // Focus --------------------------------------------------------------------- |
1540 | 1543 |
1541 // Next view to be focused when the Tab key is pressed. | 1544 // Next view to be focused when the Tab key is pressed. |
1542 View* next_focusable_view_; | 1545 View* next_focusable_view_; |
1543 | 1546 |
1544 // Next view to be focused when the Shift-Tab key combination is pressed. | 1547 // Next view to be focused when the Shift-Tab key combination is pressed. |
1545 View* previous_focusable_view_; | 1548 View* previous_focusable_view_; |
1546 | 1549 |
1547 // Whether this view can be focused. | 1550 // The focus behavior of the view in regular and accessibility mode. |
1548 bool focusable_; | 1551 FocusBehavior focus_behavior_; |
1549 | |
1550 // Whether this view is focusable if the user requires full keyboard access, | |
1551 // even though it may not be normally focusable. | |
1552 bool accessibility_focusable_; | |
1553 | 1552 |
1554 // Context menus ------------------------------------------------------------- | 1553 // Context menus ------------------------------------------------------------- |
1555 | 1554 |
1556 // The menu controller. | 1555 // The menu controller. |
1557 ContextMenuController* context_menu_controller_; | 1556 ContextMenuController* context_menu_controller_; |
1558 | 1557 |
1559 // Drag and drop ------------------------------------------------------------- | 1558 // Drag and drop ------------------------------------------------------------- |
1560 | 1559 |
1561 DragController* drag_controller_; | 1560 DragController* drag_controller_; |
1562 | 1561 |
1563 // Input -------------------------------------------------------------------- | 1562 // Input -------------------------------------------------------------------- |
1564 | 1563 |
1565 std::unique_ptr<ViewTargeter> targeter_; | 1564 std::unique_ptr<ViewTargeter> targeter_; |
1566 | 1565 |
1567 // Accessibility ------------------------------------------------------------- | 1566 // Accessibility ------------------------------------------------------------- |
1568 | 1567 |
1569 // Belongs to this view, but it's reference-counted on some platforms | 1568 // Belongs to this view, but it's reference-counted on some platforms |
1570 // so we can't use a scoped_ptr. It's dereferenced in the destructor. | 1569 // so we can't use a scoped_ptr. It's dereferenced in the destructor. |
1571 NativeViewAccessibility* native_view_accessibility_; | 1570 NativeViewAccessibility* native_view_accessibility_; |
1572 | 1571 |
1573 DISALLOW_COPY_AND_ASSIGN(View); | 1572 DISALLOW_COPY_AND_ASSIGN(View); |
1574 }; | 1573 }; |
1575 | 1574 |
1576 } // namespace views | 1575 } // namespace views |
1577 | 1576 |
1578 #endif // UI_VIEWS_VIEW_H_ | 1577 #endif // UI_VIEWS_VIEW_H_ |
OLD | NEW |