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

Side by Side Diff: ui/views/view.h

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted to common code into FocusManager class Created 7 years 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) 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 <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // Gets the maximum size of the view. Currently only used for sizing shell 270 // Gets the maximum size of the view. Currently only used for sizing shell
271 // windows. 271 // windows.
272 virtual gfx::Size GetMaximumSize(); 272 virtual gfx::Size GetMaximumSize();
273 273
274 // Return the height necessary to display this view with the provided width. 274 // Return the height necessary to display this view with the provided width.
275 // View's implementation returns the value from getPreferredSize.cy. 275 // View's implementation returns the value from getPreferredSize.cy.
276 // Override if your View's preferred height depends upon the width (such 276 // Override if your View's preferred height depends upon the width (such
277 // as with Labels). 277 // as with Labels).
278 virtual int GetHeightForWidth(int w); 278 virtual int GetHeightForWidth(int w);
279 279
280 // Set whether this view is visible. Painting is scheduled as needed. 280 // Sets whether this view is visible. Painting is scheduled as needed. Also,
281 // clears focus if the focused view or one of its ancestors is set to be
282 // hidden.
281 virtual void SetVisible(bool visible); 283 virtual void SetVisible(bool visible);
282 284
283 // Return whether a view is visible 285 // Return whether a view is visible
284 bool visible() const { return visible_; } 286 bool visible() const { return visible_; }
285 287
286 // Returns true if this view is drawn on screen. 288 // Returns true if this view is drawn on screen.
287 virtual bool IsDrawn() const; 289 virtual bool IsDrawn() const;
288 290
289 // Set whether this view is enabled. A disabled view does not receive keyboard 291 // Set whether this view is enabled. A disabled view does not receive keyboard
290 // or mouse inputs. If |enabled| differs from the current value, SchedulePaint 292 // or mouse inputs. If |enabled| differs from the current value, SchedulePaint
291 // is invoked. 293 // is invoked. Also, clears focus if the focused view is disabled.
292 void SetEnabled(bool enabled); 294 void SetEnabled(bool enabled);
293 295
294 // Returns whether the view is enabled. 296 // Returns whether the view is enabled.
295 bool enabled() const { return enabled_; } 297 bool enabled() const { return enabled_; }
296 298
297 // This indicates that the view completely fills its bounds in an opaque 299 // This indicates that the view completely fills its bounds in an opaque
298 // color. This doesn't affect compositing but is a hint to the compositor to 300 // color. This doesn't affect compositing but is a hint to the compositor to
299 // optimize painting. 301 // optimize painting.
300 // Note that this method does not implicitly create a layer if one does not 302 // Note that this method does not implicitly create a layer if one does not
301 // already exist for the View, but is a no-op in that case. 303 // already exist for the View, but is a no-op in that case.
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // Returns the view that should be selected next when pressing Shift-Tab. 760 // Returns the view that should be selected next when pressing Shift-Tab.
759 View* GetPreviousFocusableView(); 761 View* GetPreviousFocusableView();
760 762
761 // Sets the component that should be selected next when pressing Tab, and 763 // Sets the component that should be selected next when pressing Tab, and
762 // makes the current view the precedent view of the specified one. 764 // makes the current view the precedent view of the specified one.
763 // Note that by default views are linked in the order they have been added to 765 // Note that by default views are linked in the order they have been added to
764 // their container. Use this method if you want to modify the order. 766 // their container. Use this method if you want to modify the order.
765 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. 767 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
766 void SetNextFocusableView(View* view); 768 void SetNextFocusableView(View* view);
767 769
768 // Sets whether this view is capable of taking focus. 770 // Sets whether this view is capable of taking focus. It will clear focus if
771 // the focused view is set to be non-focusable.
769 // Note that this is false by default so that a view used as a container does 772 // Note that this is false by default so that a view used as a container does
770 // not get the focus. 773 // not get the focus.
771 void set_focusable(bool focusable) { focusable_ = focusable; } 774 void SetFocusable(bool focusable);
772 775
773 // Returns true if this view is capable of taking focus. 776 // Returns true if this view is capable of taking focus.
774 bool focusable() const { return focusable_ && enabled_ && visible_; } 777 bool focusable() const { return focusable_ && enabled_ && visible_; }
775 778
776 // Returns true if this view is |focusable_|, |enabled_| and drawn. 779 // Returns true if this view is |focusable_|, |enabled_| and drawn.
777 virtual bool IsFocusable() const; 780 virtual bool IsFocusable() const;
778 781
779 // Return whether this view is focusable when the user requires full keyboard 782 // Return whether this view is focusable when the user requires full keyboard
780 // access, even though it may not be normally focusable. 783 // access, even though it may not be normally focusable.
781 bool IsAccessibilityFocusable() const; 784 bool IsAccessibilityFocusable() const;
782 785
783 // Set whether this view can be made focusable if the user requires 786 // Set whether this view can be made focusable if the user requires
784 // full keyboard access, even though it's not normally focusable. 787 // full keyboard access, even though it's not normally focusable. It will
788 // clear focus if the focused view is set to be non-focusable.
785 // Note that this is false by default. 789 // Note that this is false by default.
786 void set_accessibility_focusable(bool accessibility_focusable) { 790 void SetAccessibilityFocusable(bool accessibility_focusable);
787 accessibility_focusable_ = accessibility_focusable;
788 }
789 791
790 // Convenience method to retrieve the FocusManager associated with the 792 // Convenience method to retrieve the FocusManager associated with the
791 // 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
792 // part of a view hierarchy with a Widget. 794 // part of a view hierarchy with a Widget.
793 virtual FocusManager* GetFocusManager(); 795 virtual FocusManager* GetFocusManager();
794 virtual const FocusManager* GetFocusManager() const; 796 virtual const FocusManager* GetFocusManager() const;
795 797
796 // Request keyboard focus. The receiving view will become the focused view. 798 // Request keyboard focus. The receiving view will become the focused view.
797 virtual void RequestFocus(); 799 virtual void RequestFocus();
798 800
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 // |leave_data_intact| if true does not remove data from accelerators_ array, 1385 // |leave_data_intact| if true does not remove data from accelerators_ array,
1384 // so it could be re-registered with other focus manager 1386 // so it could be re-registered with other focus manager
1385 void UnregisterAccelerators(bool leave_data_intact); 1387 void UnregisterAccelerators(bool leave_data_intact);
1386 1388
1387 // Focus --------------------------------------------------------------------- 1389 // Focus ---------------------------------------------------------------------
1388 1390
1389 // Initialize the previous/next focusable views of the specified view relative 1391 // Initialize the previous/next focusable views of the specified view relative
1390 // to the view at the specified index. 1392 // to the view at the specified index.
1391 void InitFocusSiblings(View* view, int index); 1393 void InitFocusSiblings(View* view, int index);
1392 1394
1395 // Clears the focused view if it has become unfocusable.
1396 void ClearFocusIfUnfocusable();
1397
1393 // System events ------------------------------------------------------------- 1398 // System events -------------------------------------------------------------
1394 1399
1395 // Used to propagate theme changed notifications from the root view to all 1400 // Used to propagate theme changed notifications from the root view to all
1396 // views in the hierarchy. 1401 // views in the hierarchy.
1397 virtual void PropagateThemeChanged(); 1402 virtual void PropagateThemeChanged();
1398 1403
1399 // Used to propagate locale changed notifications from the root view to all 1404 // Used to propagate locale changed notifications from the root view to all
1400 // views in the hierarchy. 1405 // views in the hierarchy.
1401 virtual void PropagateLocaleChanged(); 1406 virtual void PropagateLocaleChanged();
1402 1407
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 // Belongs to this view, but it's reference-counted on some platforms 1562 // Belongs to this view, but it's reference-counted on some platforms
1558 // so we can't use a scoped_ptr. It's dereferenced in the destructor. 1563 // so we can't use a scoped_ptr. It's dereferenced in the destructor.
1559 NativeViewAccessibility* native_view_accessibility_; 1564 NativeViewAccessibility* native_view_accessibility_;
1560 1565
1561 DISALLOW_COPY_AND_ASSIGN(View); 1566 DISALLOW_COPY_AND_ASSIGN(View);
1562 }; 1567 };
1563 1568
1564 } // namespace views 1569 } // namespace views
1565 1570
1566 #endif // UI_VIEWS_VIEW_H_ 1571 #endif // UI_VIEWS_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698