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

Side by Side Diff: views/view.h

Issue 7057014: Variety of tweaks to View API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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/layout/box_layout.cc ('k') | views/view.cc » ('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 #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
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // TODO(beng): Figure out what these methods are for and delete them. 177 // TODO(beng): Figure out what these methods are for and delete them.
178 178
179 // TODO(beng): this one isn't even google3-style. wth. 179 // TODO(beng): this one isn't even google3-style. wth.
180 virtual Widget* child_widget(); 180 virtual Widget* child_widget();
181 181
182 // Creation and lifetime ----------------------------------------------------- 182 // Creation and lifetime -----------------------------------------------------
183 183
184 View(); 184 View();
185 virtual ~View(); 185 virtual ~View();
186 186
187 // Set whether this view is owned by its parent. A view that is owned by its 187 // By default a View is owned by its parent unless specified otherwise here.
188 // parent is automatically deleted when the parent is deleted. The default is 188 bool parent_owned() const { return parent_owned_; }
189 // true. Set to false if the view is owned by another object and should not 189 void set_parent_owned(bool parent_owned) { parent_owned_ = parent_owned; }
190 // be deleted by its parent.
191 void set_parent_owned(bool is_parent_owned) {
192 is_parent_owned_ = is_parent_owned;
193 }
194
195 // Return whether a view is owned by its parent.
196 bool IsParentOwned() const { return is_parent_owned_; }
197 190
198 // Tree operations ----------------------------------------------------------- 191 // Tree operations -----------------------------------------------------------
199 192
200 // Get the Widget that hosts this View, if any. 193 // Get the Widget that hosts this View, if any.
201 virtual const Widget* GetWidget() const; 194 virtual const Widget* GetWidget() const;
202 virtual Widget* GetWidget(); 195 virtual Widget* GetWidget();
203 196
197 // Returns the containing Window. Although Window is a Widget subclass, this
198 // function may not return the same value as GetWidget() above since this View
199 // may be a child of a Widget nested within a Window. This function will
200 // return the nearest containing Window in the Widget hierarchy. The View may
201 // not be contained in a Window Widget, in which case this function will
202 // return NULL.
203 virtual const Window* GetWindow() const;
204 virtual Window* GetWindow();
205
204 // Add a child View, optionally at |index|. 206 // Add a child View, optionally at |index|.
205 void AddChildView(View* view); 207 void AddChildView(View* view);
206 void AddChildViewAt(View* view, int index); 208 void AddChildViewAt(View* view, int index);
207 209
208 // Remove a child view from this view. The view's parent will change to NULL. 210 // Remove a child view from this view. The view's parent will change to NULL.
209 void RemoveChildView(View* views); 211 void RemoveChildView(View* views);
210 212
211 // Remove all child view from this view. If |delete_views| is true, the views 213 // Remove all child view from this view. If |delete_views| is true, the views
212 // are deleted, unless marked as not parent owned. 214 // are deleted, unless marked as not parent owned.
213 void RemoveAllChildViews(bool delete_views); 215 void RemoveAllChildViews(bool delete_views);
(...skipping 11 matching lines...) Expand all
225 View* parent() { return parent_; } 227 View* parent() { return parent_; }
226 228
227 // Returns true if |child| is contained within this View's hierarchy, even as 229 // Returns true if |child| is contained within this View's hierarchy, even as
228 // an indirect descendant. Will return true if child is also this View. 230 // an indirect descendant. Will return true if child is also this View.
229 bool Contains(const View* view) const; 231 bool Contains(const View* view) const;
230 232
231 // Returns the index of the specified |view| in this view's children, or -1 233 // Returns the index of the specified |view| in this view's children, or -1
232 // if the specified view is not a child of this view. 234 // if the specified view is not a child of this view.
233 int GetIndexOf(const View* view) const; 235 int GetIndexOf(const View* view) const;
234 236
235 // TODO(beng): REMOVE (Views need not know about Window).
236 // Gets the Widget that most closely contains this View, if any.
237 // NOTE: almost all views displayed on screen have a Widget, but not
238 // necessarily a Window. This is due to widgets being able to create top
239 // level windows (as is done for popups, bubbles and menus).
240 virtual const Window* GetWindow() const;
241 virtual Window* GetWindow();
242
243 // TODO(beng): REMOVE (TBD) 237 // TODO(beng): REMOVE (TBD)
244 // 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
245 // hierarchy beneath this view. 239 // hierarchy beneath this view.
246 virtual bool ContainsNativeView(gfx::NativeView native_view) const; 240 virtual bool ContainsNativeView(gfx::NativeView native_view) const;
247 241
248 // Size and disposition ------------------------------------------------------ 242 // Size and disposition ------------------------------------------------------
249 // Methods for obtaining and modifying the position and size of the view. 243 // Methods for obtaining and modifying the position and size of the view.
250 // Position is in the coordinate system of the view's parent. 244 // Position is in the coordinate system of the view's parent.
251 // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive 245 // Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive
252 // position accessors. 246 // position accessors.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // therefore it will return the mirrored version of the visible bounds if 284 // therefore it will return the mirrored version of the visible bounds if
291 // need be. 285 // need be.
292 // TODO(beng): const. 286 // TODO(beng): const.
293 gfx::Rect GetVisibleBounds(); 287 gfx::Rect GetVisibleBounds();
294 288
295 // Return the bounds of the View in screen coordinate system. 289 // Return the bounds of the View in screen coordinate system.
296 gfx::Rect GetScreenBounds() const; 290 gfx::Rect GetScreenBounds() const;
297 291
298 // Returns the baseline of this view, or -1 if this view has no baseline. The 292 // Returns the baseline of this view, or -1 if this view has no baseline. The
299 // return value is relative to the preferred height. 293 // return value is relative to the preferred height.
294 // TODO(beng): const
300 virtual int GetBaseline(); 295 virtual int GetBaseline();
301 296
302 // Get the size the View would like to be, if enough space were available. 297 // Get the size the View would like to be, if enough space were available.
303 virtual gfx::Size GetPreferredSize(); 298 virtual gfx::Size GetPreferredSize();
304 299
305 // Convenience method that sizes this view to its preferred size. 300 // Convenience method that sizes this view to its preferred size.
306 void SizeToPreferredSize(); 301 void SizeToPreferredSize();
307 302
308 // Gets the minimum size of the view. View's implementation invokes 303 // Gets the minimum size of the view. View's implementation invokes
309 // GetPreferredSize. 304 // GetPreferredSize.
310 virtual gfx::Size GetMinimumSize(); 305 virtual gfx::Size GetMinimumSize();
311 306
312 // Return the height necessary to display this view with the provided width. 307 // Return the height necessary to display this view with the provided width.
313 // View's implementation returns the value from getPreferredSize.cy. 308 // View's implementation returns the value from getPreferredSize.cy.
314 // Override if your View's preferred height depends upon the width (such 309 // Override if your View's preferred height depends upon the width (such
315 // as with Labels). 310 // as with Labels).
316 virtual int GetHeightForWidth(int w); 311 virtual int GetHeightForWidth(int w);
317 312
318 // Set whether the receiving view is visible. Painting is scheduled as needed
319 virtual void SetVisible(bool flag);
320
321 // Return whether a view is visible
322 virtual bool IsVisible() const;
323
324 // Return whether a view and its ancestors are visible. Returns true if the
325 // path from this view to the root view is visible.
326 virtual bool IsVisibleInRootView() const;
327
328 // Set whether this view is enabled. A disabled view does not receive keyboard
329 // or mouse inputs. If flag differs from the current value, SchedulePaint is
330 // invoked.
331 virtual void SetEnabled(bool flag);
332
333 // Returns whether the view is enabled.
334 virtual bool IsEnabled() const;
335
336 // Transformations ----------------------------------------------------------- 313 // Transformations -----------------------------------------------------------
337 314
338 // Methods for setting transformations for a view (e.g. rotation, scaling). 315 // Methods for setting transformations for a view (e.g. rotation, scaling).
339 316
340 const ui::Transform& GetTransform() const; 317 const ui::Transform& GetTransform() const;
341 318
342 // Clipping parameters. Clipping happens from the right and/or bottom. The 319 // Clipping parameters. Clipping happens from the right and/or bottom. The
343 // clipping amount is in parent's coordinate system, as in, if the view is 320 // clipping amount is in parent's coordinate system, as in, if the view is
344 // rotated, then the clipping will be applied after the rotation (and other 321 // rotated, then the clipping will be applied after the rotation (and other
345 // transformations, if any). 322 // transformations, if any).
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 387
411 // Gets/Sets the Layout Manager used by this view to size and place its 388 // Gets/Sets the Layout Manager used by this view to size and place its
412 // children. 389 // children.
413 // The LayoutManager is owned by the View and is deleted when the view is 390 // The LayoutManager is owned by the View and is deleted when the view is
414 // deleted, or when a new LayoutManager is installed. 391 // deleted, or when a new LayoutManager is installed.
415 LayoutManager* GetLayoutManager() const; 392 LayoutManager* GetLayoutManager() const;
416 void SetLayoutManager(LayoutManager* layout); 393 void SetLayoutManager(LayoutManager* layout);
417 394
418 // Attributes ---------------------------------------------------------------- 395 // Attributes ----------------------------------------------------------------
419 396
397 // If a View is not visible, it will not be painted, focusable, etc.
398 bool visible() const { return visible_; }
399 // TODO(beng): Should not be virtual. ExtensionView, AccessiblePaneView.
400 virtual void SetVisible(bool flag);
401
402 // Return whether a view and its ancestors are visible. Returns true if the
403 // path from this view to the root view is visible.
404 // TODO(beng): Consider replacing visible() with this, since it is a more
405 // reliable test of View visibility.
406 virtual bool IsVisibleInRootView() const;
407
408 // Disabled Views will not receive mouse press or release events, and will not
409 // be focused.
410 // TODO(beng): This method should not be virtual and instead be a simple
411 // accessor.
412 virtual bool IsEnabled() const;
413 // TODO(beng): This method should not be virtual. Those methods overriding
414 // this should receive a state notification change instead.
415 virtual void SetEnabled(bool enabled);
416
420 // The view class name. 417 // The view class name.
421 static char kViewClassName[]; 418 static char kViewClassName[];
422 419
423 // Return the receiving view's class name. A view class is a string which 420 // Return the receiving view's class name. A view class is a string which
424 // uniquely identifies the view class. It is intended to be used as a way to 421 // uniquely identifies the view class. It is intended to be used as a way to
425 // find out during run time if a view can be safely casted to a specific view 422 // find out during run time if a view can be safely casted to a specific view
426 // subclass. The default implementation returns kViewClassName. 423 // subclass. The default implementation returns kViewClassName.
427 virtual std::string GetClassName() const; 424 virtual std::string GetClassName() const;
428 425
429 // Returns the first ancestor, starting at this, whose class name is |name|. 426 // Returns the first ancestor, starting at this, whose class name is |name|.
430 // Returns null if no ancestor has the class name |name|. 427 // Returns null if no ancestor has the class name |name|.
431 View* GetAncestorWithClassName(const std::string& name); 428 View* GetAncestorWithClassName(const std::string& name);
432 429
433 // Recursively descends the view tree starting at this view, and returns 430 // Recursively descends the view tree starting at this view, and returns
434 // the first child that it encounters that has the given ID. 431 // the first child that it encounters that has the given ID.
435 // Returns NULL if no matching child view is found. 432 // Returns NULL if no matching child view is found.
436 virtual const View* GetViewByID(int id) const; 433 virtual const View* GetViewByID(int id) const;
437 virtual View* GetViewByID(int id); 434 virtual View* GetViewByID(int id);
438 435
439 // Sets and gets the ID for this view. ID should be unique within the subtree 436 // Sets and gets the ID for this view. ID should be unique within the subtree
440 // that you intend to search for it. 0 is the default ID for views. 437 // that you intend to search for it. 0 is the default ID for views.
441 void SetID(int id); 438 int id() const { return id_; }
442 int GetID() const; 439 void set_id(int id) { id_ = id; }
443 440
444 // A group id is used to tag views which are part of the same logical group. 441 // A group id is used to tag views which are part of the same logical control
445 // Focus can be moved between views with the same group using the arrow keys. 442 // group. Focus can be moved between views with the same group using the arrow
446 // Groups are currently used to implement radio button mutual exclusion. 443 // keys. Groups are currently used to implement radio button mutual exclusion.
447 // The group id is immutable once it's set. 444 // The group id defaults to -1 for all Views and is immutable once set.
448 void SetGroup(int gid); 445 int group() const { return group_; }
449 // Returns the group id of the view, or -1 if the id is not set yet. 446 void set_group(int group);
450 int GetGroup() const;
451 447
452 // If this returns true, the views from the same group can each be focused 448 // If this returns true, the views from the same group can each be focused
453 // when moving focus with the Tab/Shift-Tab key. If this returns false, 449 // when moving focus with the Tab/Shift-Tab key. If this returns false,
454 // only the selected view from the group (obtained with 450 // only the selected view from the group (obtained with
455 // GetSelectedViewForGroup()) is focused. 451 // GetSelectedViewForGroup()) is focused.
456 virtual bool IsGroupFocusTraversable() const; 452 virtual bool IsGroupFocusTraversable() const;
457 453
458 // Fills the provided vector with all the available views which belong to the 454 // Fills the provided vector with all the available views which belong to the
459 // provided group. 455 // provided group.
460 void GetViewsWithGroup(int group_id, std::vector<View*>* out); 456 void GetViewsInGroup(int group, std::vector<View*>* out);
461 457
462 // Return the View that is currently selected in the specified group. 458 // Return the View that is currently selected in the specified group.
463 // The default implementation simply returns the first View found for that 459 // The default implementation simply returns the first View found for that
464 // group. 460 // group.
465 virtual View* GetSelectedViewForGroup(int group_id); 461 virtual View* GetSelectedViewForGroup(int group);
466 462
467 // Coordinate conversion ----------------------------------------------------- 463 // Coordinate conversion -----------------------------------------------------
468 464
469 // Note that the utility coordinate conversions functions always operate on 465 // Note that the utility coordinate conversions functions always operate on
470 // the mirrored position of the child Views if the parent View uses a 466 // the mirrored position of the child Views if the parent View uses a
471 // right-to-left UI layout. 467 // right-to-left UI layout.
472 468
473 // Convert a point from source coordinate system to dst coordinate system. 469 // Convert a point from source coordinate system to dst coordinate system.
474 // 470 //
475 // |src| and |dst| needs to be in the same widget, but doesn't need to be in 471 // |src| and |dst| needs to be in the same widget, but doesn't need to be in
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // Sets the component that should be selected next when pressing Tab, and 712 // Sets the component that should be selected next when pressing Tab, and
717 // makes the current view the precedent view of the specified one. 713 // makes the current view the precedent view of the specified one.
718 // Note that by default views are linked in the order they have been added to 714 // Note that by default views are linked in the order they have been added to
719 // their container. Use this method if you want to modify the order. 715 // their container. Use this method if you want to modify the order.
720 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. 716 // IMPORTANT NOTE: loops in the focus hierarchy are not supported.
721 void SetNextFocusableView(View* view); 717 void SetNextFocusableView(View* view);
722 718
723 // Sets whether this view can accept the focus. 719 // Sets whether this view can accept the focus.
724 // Note that this is false by default so that a view used as a container does 720 // Note that this is false by default so that a view used as a container does
725 // not get the focus. 721 // not get the focus.
726 virtual void SetFocusable(bool focusable); 722 void set_focusable(bool focusable) { focusable_ = focusable; }
727 723
728 // Returns true if the view is focusable (IsFocusable) and visible in the root 724 // Returns true if the view is focusable (IsFocusable) and visible in the root
729 // view. See also IsFocusable. 725 // view. See also IsFocusable.
730 bool IsFocusableInRootView() const; 726 bool IsFocusableInRootView() const;
731 727
732 // Return whether this view is focusable when the user requires full keyboard 728 // Return whether this view is focusable when the user requires full keyboard
733 // access, even though it may not be normally focusable. 729 // access, even though it may not be normally focusable.
734 bool IsAccessibilityFocusableInRootView() const; 730 bool IsAccessibilityFocusableInRootView() const;
735 731
736 // Set whether this view can be made focusable if the user requires 732 // Set whether this view can be made focusable if the user requires
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, 1154 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1159 // the next and previous focusable views of views pointing to this view are 1155 // the next and previous focusable views of views pointing to this view are
1160 // updated. If |update_tool_tip| is true, the tooltip is updated. If 1156 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1161 // |delete_removed_view| is true, the view is also deleted (if it is parent 1157 // |delete_removed_view| is true, the view is also deleted (if it is parent
1162 // owned). 1158 // owned).
1163 void DoRemoveChildView(View* view, 1159 void DoRemoveChildView(View* view,
1164 bool update_focus_cycle, 1160 bool update_focus_cycle,
1165 bool update_tool_tip, 1161 bool update_tool_tip,
1166 bool delete_removed_view); 1162 bool delete_removed_view);
1167 1163
1168 // Sets the parent View. This is called automatically by AddChild and is
1169 // thus private.
1170 void SetParent(View* parent);
1171
1172 // Call ViewHierarchyChanged for all child views on all parents 1164 // Call ViewHierarchyChanged for all child views on all parents
1173 void PropagateRemoveNotifications(View* parent); 1165 void PropagateRemoveNotifications(View* parent);
1174 1166
1175 // Call ViewHierarchyChanged for all children 1167 // Call ViewHierarchyChanged for all children
1176 void PropagateAddNotifications(View* parent, View* child); 1168 void PropagateAddNotifications(View* parent, View* child);
1177 1169
1178 // Propagates NativeViewHierarchyChanged() notification through all the 1170 // Propagates NativeViewHierarchyChanged() notification through all the
1179 // children. 1171 // children.
1180 void PropagateNativeViewHierarchyChanged(bool attached, 1172 void PropagateNativeViewHierarchyChanged(bool attached,
1181 gfx::NativeView native_view, 1173 gfx::NativeView native_view,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 // to a file to compile/view. 1308 // to a file to compile/view.
1317 // Note: Assumes initial call made with first = true. 1309 // Note: Assumes initial call made with first = true.
1318 std::string PrintViewGraph(bool first); 1310 std::string PrintViewGraph(bool first);
1319 #endif 1311 #endif
1320 1312
1321 ////////////////////////////////////////////////////////////////////////////// 1313 //////////////////////////////////////////////////////////////////////////////
1322 1314
1323 // Creation and lifetime ----------------------------------------------------- 1315 // Creation and lifetime -----------------------------------------------------
1324 1316
1325 // Whether this view is owned by its parent. 1317 // Whether this view is owned by its parent.
1326 bool is_parent_owned_; 1318 bool parent_owned_;
1327 1319
1328 // Tree operations ----------------------------------------------------------- 1320 // Tree operations -----------------------------------------------------------
1329 1321
1330 // This view's parent 1322 // This view's parent
1331 View* parent_; 1323 View* parent_;
1332 1324
1333 // This view's children. 1325 // This view's children.
1334 typedef std::vector<View*> ViewVector; 1326 typedef std::vector<View*> ViewVector;
1335 ViewVector children_; 1327 ViewVector children_;
1336 1328
1337 // Size and disposition ------------------------------------------------------ 1329 // Size and disposition ------------------------------------------------------
1338 1330
1339 // This View's bounds in the parent coordinate system. 1331 // This View's bounds in the parent coordinate system.
1340 gfx::Rect bounds_; 1332 gfx::Rect bounds_;
1341 1333
1342 // Visible state 1334 // Visible state
1343 bool is_visible_; 1335 bool visible_;
1344 1336
1345 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView 1337 // Whether or not RegisterViewForVisibleBoundsNotification on the RootView
1346 // has been invoked. 1338 // has been invoked.
1347 bool registered_for_visible_bounds_notification_; 1339 bool registered_for_visible_bounds_notification_;
1348 1340
1349 // List of descendants wanting notification when their visible bounds change. 1341 // List of descendants wanting notification when their visible bounds change.
1350 scoped_ptr<ViewVector> descendants_to_notify_; 1342 scoped_ptr<ViewVector> descendants_to_notify_;
1351 1343
1352 // Transformations ----------------------------------------------------------- 1344 // Transformations -----------------------------------------------------------
1353 1345
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 // The Windows-specific accessibility implementation for this View. 1435 // The Windows-specific accessibility implementation for this View.
1444 scoped_refptr<NativeViewAccessibilityWin> native_view_accessibility_win_; 1436 scoped_refptr<NativeViewAccessibilityWin> native_view_accessibility_win_;
1445 #endif 1437 #endif
1446 1438
1447 DISALLOW_COPY_AND_ASSIGN(View); 1439 DISALLOW_COPY_AND_ASSIGN(View);
1448 }; 1440 };
1449 1441
1450 } // namespace views 1442 } // namespace views
1451 1443
1452 #endif // VIEWS_VIEW_H_ 1444 #endif // VIEWS_VIEW_H_
OLDNEW
« no previous file with comments | « views/layout/box_layout.cc ('k') | views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698