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

Side by Side Diff: views/view.h

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
OLDNEW
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
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, size_t 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(size_t index) const;
211 View* GetChildViewAt(size_t index);
212
210 // Get the number of child Views. 213 // Get the number of child Views.
211 int GetChildViewCount() const; 214 size_t child_count() const { return 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 size_t GetIndexOf(const View* view) const;
sky 2011/02/08 19:11:54 This can never return -1 now. I'm inclined to thin
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
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
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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 1295
1299 // Whether this view is owned by its parent. 1296 // Whether this view is owned by its parent.
1300 bool is_parent_owned_; 1297 bool is_parent_owned_;
1301 1298
1302 // Tree operations ----------------------------------------------------------- 1299 // Tree operations -----------------------------------------------------------
1303 1300
1304 // This view's parent 1301 // This view's parent
1305 View* parent_; 1302 View* parent_;
1306 1303
1307 // This view's children. 1304 // This view's children.
1308 typedef std::vector<View*> ViewList; 1305 typedef std::vector<View*> ViewVector;
sky 2011/02/08 19:11:54 all typedefs should be grouped together.
1309 ViewList child_views_; 1306 ViewVector children_;
1310 1307
1311 // Size and disposition ------------------------------------------------------ 1308 // Size and disposition ------------------------------------------------------
1312 1309
1313 // This View's bounds in the parent coordinate system. 1310 // This View's bounds in the parent coordinate system.
1314 gfx::Rect bounds_; 1311 gfx::Rect bounds_;
1315 1312
1316 // Visible state 1313 // Visible state
1317 bool is_visible_; 1314 bool is_visible_;
1318 1315
1319 // See SetNotifyWhenVisibleBoundsInRootChanges. 1316 // See SetNotifyWhenVisibleBoundsInRootChanges.
1320 bool notify_when_visible_bounds_in_root_changes_; 1317 bool notify_when_visible_bounds_in_root_changes_;
1321 1318
1322 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView 1319 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1323 // has been invoked. 1320 // has been invoked.
1324 bool registered_for_visible_bounds_notification_; 1321 bool registered_for_visible_bounds_notification_;
1325 1322
1326 // List of descendants wanting notification when their visible bounds change. 1323 // List of descendants wanting notification when their visible bounds change.
1327 scoped_ptr<ViewList> descendants_to_notify_; 1324 scoped_ptr<ViewVector> descendants_to_notify_;
1328 1325
1329 // Layout -------------------------------------------------------------------- 1326 // Layout --------------------------------------------------------------------
1330 1327
1331 // Whether the view needs to be laid out. 1328 // Whether the view needs to be laid out.
1332 bool needs_layout_; 1329 bool needs_layout_;
1333 1330
1334 // The View's LayoutManager defines the sizing heuristics applied to child 1331 // The View's LayoutManager defines the sizing heuristics applied to child
1335 // Views. The default is absolute positioning according to bounds_. 1332 // Views. The default is absolute positioning according to bounds_.
1336 scoped_ptr<LayoutManager> layout_manager_; 1333 scoped_ptr<LayoutManager> layout_manager_;
1337 1334
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 // The accessibility implementation for this View. 1388 // The accessibility implementation for this View.
1392 scoped_refptr<ViewAccessibility> view_accessibility_; 1389 scoped_refptr<ViewAccessibility> view_accessibility_;
1393 #endif 1390 #endif
1394 1391
1395 DISALLOW_COPY_AND_ASSIGN(View); 1392 DISALLOW_COPY_AND_ASSIGN(View);
1396 }; 1393 };
1397 1394
1398 } // namespace views 1395 } // namespace views
1399 1396
1400 #endif // VIEWS_VIEW_H_ 1397 #endif // VIEWS_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698