| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 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 #ifndef VIEWS_VIEW_H_ | 5 #ifndef VIEWS_VIEW_H_ | 
| 6 #define VIEWS_VIEW_H_ | 6 #define VIEWS_VIEW_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" | 
| 10 | 10 | 
| 11 #include <algorithm> | 11 #include <algorithm> | 
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 184   // be deleted by its parent. | 184   // be deleted by its parent. | 
| 185   void set_parent_owned(bool is_parent_owned) { | 185   void set_parent_owned(bool is_parent_owned) { | 
| 186     is_parent_owned_ = is_parent_owned; | 186     is_parent_owned_ = is_parent_owned; | 
| 187   } | 187   } | 
| 188 | 188 | 
| 189   // Return whether a view is owned by its parent. | 189   // Return whether a view is owned by its parent. | 
| 190   bool IsParentOwned() const { return is_parent_owned_; } | 190   bool IsParentOwned() const { return is_parent_owned_; } | 
| 191 | 191 | 
| 192   // Tree operations ----------------------------------------------------------- | 192   // Tree operations ----------------------------------------------------------- | 
| 193 | 193 | 
| 194   // Add a child View. | 194   // Get the Widget that hosts this View, if any. | 
| 195   void AddChildView(View* v); | 195   virtual const Widget* GetWidget() const; | 
|  | 196   virtual Widget* GetWidget(); | 
| 196 | 197 | 
| 197   // Adds a child View at the specified position. | 198   // Add a child View, optionally at |index|. | 
| 198   void AddChildView(int index, View* v); | 199   void AddChildView(View* view); | 
|  | 200   void AddChildViewAt(View* view, int index); | 
| 199 | 201 | 
| 200   // Get the child View at the specified index. | 202   // Remove a child view from this view. The view's parent will change to NULL. | 
| 201   View* GetChildViewAt(int index) const; | 203   void RemoveChildView(View* views); | 
| 202 |  | 
| 203   // Remove a child view from this view. v's parent will change to NULL |  | 
| 204   void RemoveChildView(View *v); |  | 
| 205 | 204 | 
| 206   // Remove all child view from this view.  If |delete_views| is true, the views | 205   // Remove all child view from this view.  If |delete_views| is true, the views | 
| 207   // are deleted, unless marked as not parent owned. | 206   // are deleted, unless marked as not parent owned. | 
| 208   void RemoveAllChildViews(bool delete_views); | 207   void RemoveAllChildViews(bool delete_views); | 
| 209 | 208 | 
|  | 209   // Returns the View at the specified |index|. | 
|  | 210   const View* GetChildViewAt(int index) const; | 
|  | 211   View* GetChildViewAt(int index); | 
|  | 212 | 
| 210   // Get the number of child Views. | 213   // Get the number of child Views. | 
| 211   int GetChildViewCount() const; | 214   int child_count() const { return static_cast<int>(children_.size()); } | 
|  | 215   bool has_children() const { return !children_.empty(); } | 
| 212 | 216 | 
| 213   // Tests if this view has a given view as direct child. | 217   // Get the parent View | 
| 214   bool HasChildView(View* a_view); | 218   const View* parent() const { return parent_; } | 
|  | 219   View* parent() { return parent_; } | 
| 215 | 220 | 
| 216   // Get the Widget that hosts this View, if any. | 221   // Returns true if |child| is contained within this View's hierarchy, even as | 
| 217   virtual Widget* GetWidget() const; | 222   // an indirect descendant. Will return true if child is also this View. | 
|  | 223   bool Contains(const View* view) const; | 
| 218 | 224 | 
|  | 225   // Returns the index of the specified |view| in this view's children, or -1 | 
|  | 226   // if the specified view is not a child of this view. | 
|  | 227   int GetIndexOf(const View* view) const; | 
|  | 228 | 
|  | 229   // TODO(beng): REMOVE (Views need not know about Window). | 
| 219   // Gets the Widget that most closely contains this View, if any. | 230   // Gets the Widget that most closely contains this View, if any. | 
| 220   // NOTE: almost all views displayed on screen have a Widget, but not | 231   // NOTE: almost all views displayed on screen have a Widget, but not | 
| 221   // necessarily a Window. This is due to widgets being able to create top | 232   // necessarily a Window. This is due to widgets being able to create top | 
| 222   // level windows (as is done for popups, bubbles and menus). | 233   // level windows (as is done for popups, bubbles and menus). | 
| 223   virtual Window* GetWindow() const; | 234   virtual const Window* GetWindow() const; | 
|  | 235   virtual Window* GetWindow(); | 
| 224 | 236 | 
|  | 237   // TODO(beng): REMOVE (TBD) | 
| 225   // Returns true if the native view |native_view| is contained in the view | 238   // Returns true if the native view |native_view| is contained in the view | 
| 226   // hierarchy beneath this view. | 239   // hierarchy beneath this view. | 
| 227   virtual bool ContainsNativeView(gfx::NativeView native_view) const; | 240   virtual bool ContainsNativeView(gfx::NativeView native_view) const; | 
| 228 | 241 | 
|  | 242   // TODO(beng): REMOVE (RootView->internal API) | 
| 229   // Get the containing RootView | 243   // Get the containing RootView | 
| 230   virtual RootView* GetRootView(); | 244   virtual RootView* GetRootView(); | 
| 231 | 245 | 
| 232   // Get the parent View |  | 
| 233   View* GetParent() const { return parent_; } |  | 
| 234 |  | 
| 235   // Returns the index of the specified |view| in this view's children, or -1 |  | 
| 236   // if the specified view is not a child of this view. |  | 
| 237   int GetChildIndex(const View* v) const; |  | 
| 238 |  | 
| 239   // Returns true if the specified view is a direct or indirect child of this |  | 
| 240   // view. |  | 
| 241   bool IsParentOf(View* v) const; |  | 
| 242 |  | 
| 243 #ifndef NDEBUG |  | 
| 244   // Debug method that logs the view hierarchy to the output. |  | 
| 245   void PrintViewHierarchy(); |  | 
| 246 |  | 
| 247   // Debug method that logs the focus traversal hierarchy to the output. |  | 
| 248   void PrintFocusHierarchy(); |  | 
| 249 #endif |  | 
| 250 |  | 
| 251   // Size and disposition ------------------------------------------------------ | 246   // Size and disposition ------------------------------------------------------ | 
| 252   // Methods for obtaining and modifying the position and size of the view. | 247   // Methods for obtaining and modifying the position and size of the view. | 
| 253   // Position is in the coordinate system of the view's parent. | 248   // Position is in the coordinate system of the view's parent. | 
| 254   // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive | 249   // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive | 
| 255   // position accessors. | 250   // position accessors. | 
| 256 | 251 | 
| 257   void SetBounds(int x, int y, int width, int height); | 252   void SetBounds(int x, int y, int width, int height); | 
| 258   void SetBoundsRect(const gfx::Rect& bounds); | 253   void SetBoundsRect(const gfx::Rect& bounds); | 
| 259   void SetSize(const gfx::Size& size); | 254   void SetSize(const gfx::Size& size); | 
| 260   void SetPosition(const gfx::Point& position); | 255   void SetPosition(const gfx::Point& position); | 
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 410   // subclass. The default implementation returns kViewClassName. | 405   // subclass. The default implementation returns kViewClassName. | 
| 411   virtual std::string GetClassName() const; | 406   virtual std::string GetClassName() const; | 
| 412 | 407 | 
| 413   // Returns the first ancestor, starting at this, whose class name is |name|. | 408   // Returns the first ancestor, starting at this, whose class name is |name|. | 
| 414   // Returns null if no ancestor has the class name |name|. | 409   // Returns null if no ancestor has the class name |name|. | 
| 415   View* GetAncestorWithClassName(const std::string& name); | 410   View* GetAncestorWithClassName(const std::string& name); | 
| 416 | 411 | 
| 417   // Recursively descends the view tree starting at this view, and returns | 412   // Recursively descends the view tree starting at this view, and returns | 
| 418   // the first child that it encounters that has the given ID. | 413   // the first child that it encounters that has the given ID. | 
| 419   // Returns NULL if no matching child view is found. | 414   // Returns NULL if no matching child view is found. | 
| 420   virtual View* GetViewByID(int id) const; | 415   virtual const View* GetViewByID(int id) const; | 
|  | 416   virtual View* GetViewByID(int id); | 
| 421 | 417 | 
| 422   // Sets and gets the ID for this view.  ID should be unique within the subtree | 418   // Sets and gets the ID for this view.  ID should be unique within the subtree | 
| 423   // that you intend to search for it.  0 is the default ID for views. | 419   // that you intend to search for it.  0 is the default ID for views. | 
| 424   void SetID(int id); | 420   void SetID(int id); | 
| 425   int GetID() const; | 421   int GetID() const; | 
| 426 | 422 | 
| 427   // A group id is used to tag views which are part of the same logical group. | 423   // A group id is used to tag views which are part of the same logical group. | 
| 428   // Focus can be moved between views with the same group using the arrow keys. | 424   // Focus can be moved between views with the same group using the arrow keys. | 
| 429   // Groups are currently used to implement radio button mutual exclusion. | 425   // Groups are currently used to implement radio button mutual exclusion. | 
| 430   // The group id is immutable once it's set. | 426   // The group id is immutable once it's set. | 
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 697     return false; | 693     return false; | 
| 698   } | 694   } | 
| 699 | 695 | 
| 700   // Focus --------------------------------------------------------------------- | 696   // Focus --------------------------------------------------------------------- | 
| 701 | 697 | 
| 702   // Returns whether this view currently has the focus. | 698   // Returns whether this view currently has the focus. | 
| 703   virtual bool HasFocus(); | 699   virtual bool HasFocus(); | 
| 704 | 700 | 
| 705   // Returns the view that should be selected next when pressing Tab. | 701   // Returns the view that should be selected next when pressing Tab. | 
| 706   View* GetNextFocusableView(); | 702   View* GetNextFocusableView(); | 
|  | 703   const View* GetNextFocusableView() const; | 
| 707 | 704 | 
| 708   // Returns the view that should be selected next when pressing Shift-Tab. | 705   // Returns the view that should be selected next when pressing Shift-Tab. | 
| 709   View* GetPreviousFocusableView(); | 706   View* GetPreviousFocusableView(); | 
| 710 | 707 | 
| 711   // Sets the component that should be selected next when pressing Tab, and | 708   // Sets the component that should be selected next when pressing Tab, and | 
| 712   // makes the current view the precedent view of the specified one. | 709   // makes the current view the precedent view of the specified one. | 
| 713   // Note that by default views are linked in the order they have been added to | 710   // Note that by default views are linked in the order they have been added to | 
| 714   // their container. Use this method if you want to modify the order. | 711   // their container. Use this method if you want to modify the order. | 
| 715   // IMPORTANT NOTE: loops in the focus hierarchy are not supported. | 712   // IMPORTANT NOTE: loops in the focus hierarchy are not supported. | 
| 716   void SetNextFocusableView(View* view); | 713   void SetNextFocusableView(View* view); | 
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1187                                            gfx::NativeView native_view, | 1184                                            gfx::NativeView native_view, | 
| 1188                                            RootView* root_view); | 1185                                            RootView* root_view); | 
| 1189 | 1186 | 
| 1190   // Takes care of registering/unregistering accelerators if | 1187   // Takes care of registering/unregistering accelerators if | 
| 1191   // |register_accelerators| true and calls ViewHierarchyChanged(). | 1188   // |register_accelerators| true and calls ViewHierarchyChanged(). | 
| 1192   void ViewHierarchyChangedImpl(bool register_accelerators, | 1189   void ViewHierarchyChangedImpl(bool register_accelerators, | 
| 1193                                 bool is_add, | 1190                                 bool is_add, | 
| 1194                                 View* parent, | 1191                                 View* parent, | 
| 1195                                 View* child); | 1192                                 View* child); | 
| 1196 | 1193 | 
| 1197   // Actual implementation of PrintFocusHierarchy. |  | 
| 1198   void PrintViewHierarchyImp(int indent); |  | 
| 1199   void PrintFocusHierarchyImp(int indent); |  | 
| 1200 |  | 
| 1201   // Size and disposition ------------------------------------------------------ | 1194   // Size and disposition ------------------------------------------------------ | 
| 1202 | 1195 | 
| 1203   // Call VisibilityChanged() recursively for all children. | 1196   // Call VisibilityChanged() recursively for all children. | 
| 1204   void PropagateVisibilityNotifications(View* from, bool is_visible); | 1197   void PropagateVisibilityNotifications(View* from, bool is_visible); | 
| 1205 | 1198 | 
| 1206   // Registers/unregisters accelerators as necessary and calls | 1199   // Registers/unregisters accelerators as necessary and calls | 
| 1207   // VisibilityChanged(). | 1200   // VisibilityChanged(). | 
| 1208   void VisibilityChangedImpl(View* starting_from, bool is_visible); | 1201   void VisibilityChangedImpl(View* starting_from, bool is_visible); | 
| 1209 | 1202 | 
| 1210   // Recursively descends through all descendant views, | 1203   // Recursively descends through all descendant views, | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1298 | 1291 | 
| 1299   // Whether this view is owned by its parent. | 1292   // Whether this view is owned by its parent. | 
| 1300   bool is_parent_owned_; | 1293   bool is_parent_owned_; | 
| 1301 | 1294 | 
| 1302   // Tree operations ----------------------------------------------------------- | 1295   // Tree operations ----------------------------------------------------------- | 
| 1303 | 1296 | 
| 1304   // This view's parent | 1297   // This view's parent | 
| 1305   View* parent_; | 1298   View* parent_; | 
| 1306 | 1299 | 
| 1307   // This view's children. | 1300   // This view's children. | 
| 1308   typedef std::vector<View*> ViewList; | 1301   typedef std::vector<View*> ViewVector; | 
| 1309   ViewList child_views_; | 1302   ViewVector children_; | 
| 1310 | 1303 | 
| 1311   // Size and disposition ------------------------------------------------------ | 1304   // Size and disposition ------------------------------------------------------ | 
| 1312 | 1305 | 
| 1313   // This View's bounds in the parent coordinate system. | 1306   // This View's bounds in the parent coordinate system. | 
| 1314   gfx::Rect bounds_; | 1307   gfx::Rect bounds_; | 
| 1315 | 1308 | 
| 1316   // Visible state | 1309   // Visible state | 
| 1317   bool is_visible_; | 1310   bool is_visible_; | 
| 1318 | 1311 | 
| 1319   // See SetNotifyWhenVisibleBoundsInRootChanges. | 1312   // See SetNotifyWhenVisibleBoundsInRootChanges. | 
| 1320   bool notify_when_visible_bounds_in_root_changes_; | 1313   bool notify_when_visible_bounds_in_root_changes_; | 
| 1321 | 1314 | 
| 1322   // Whether or not RegisterViewForVisibleBoundsNotification on the RootView | 1315   // Whether or not RegisterViewForVisibleBoundsNotification on the RootView | 
| 1323   // has been invoked. | 1316   // has been invoked. | 
| 1324   bool registered_for_visible_bounds_notification_; | 1317   bool registered_for_visible_bounds_notification_; | 
| 1325 | 1318 | 
| 1326   // List of descendants wanting notification when their visible bounds change. | 1319   // List of descendants wanting notification when their visible bounds change. | 
| 1327   scoped_ptr<ViewList> descendants_to_notify_; | 1320   scoped_ptr<ViewVector> descendants_to_notify_; | 
| 1328 | 1321 | 
| 1329   // Layout -------------------------------------------------------------------- | 1322   // Layout -------------------------------------------------------------------- | 
| 1330 | 1323 | 
| 1331   // Whether the view needs to be laid out. | 1324   // Whether the view needs to be laid out. | 
| 1332   bool needs_layout_; | 1325   bool needs_layout_; | 
| 1333 | 1326 | 
| 1334   // The View's LayoutManager defines the sizing heuristics applied to child | 1327   // The View's LayoutManager defines the sizing heuristics applied to child | 
| 1335   // Views. The default is absolute positioning according to bounds_. | 1328   // Views. The default is absolute positioning according to bounds_. | 
| 1336   scoped_ptr<LayoutManager> layout_manager_; | 1329   scoped_ptr<LayoutManager> layout_manager_; | 
| 1337 | 1330 | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1391   // The accessibility implementation for this View. | 1384   // The accessibility implementation for this View. | 
| 1392   scoped_refptr<ViewAccessibility> view_accessibility_; | 1385   scoped_refptr<ViewAccessibility> view_accessibility_; | 
| 1393 #endif | 1386 #endif | 
| 1394 | 1387 | 
| 1395   DISALLOW_COPY_AND_ASSIGN(View); | 1388   DISALLOW_COPY_AND_ASSIGN(View); | 
| 1396 }; | 1389 }; | 
| 1397 | 1390 | 
| 1398 }  // namespace views | 1391 }  // namespace views | 
| 1399 | 1392 | 
| 1400 #endif  // VIEWS_VIEW_H_ | 1393 #endif  // VIEWS_VIEW_H_ | 
| OLD | NEW | 
|---|