license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 5 | #ifndef CHROME_VIEWS_VIEW_H_ |
| 6 | #define CHROME_VIEWS_VIEW_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <map> |
| 9 | #include <vector> |
| 10 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 11 | // TODO(maruel): Remove these once WTL::CRect and WTL::CPoint are no more used. |
| 12 | #include <atlbase.h> |
| 13 | #include <atlapp.h> |
| 14 | #include <atlmisc.h> |
| 15 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/gfx/rect.h" |
| 17 | #include "base/scoped_ptr.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/views/accelerator.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 20 | namespace gfx { |
| 21 | class Insets; |
[email protected] | 82739cf | 2008-09-16 00:37:56 | [diff] [blame] | 22 | class Path; |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | class AccessibleWrapper; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | class ChromeCanvas; |
| 27 | class OSExchangeData; |
| 28 | class SkBitmap; |
| 29 | |
| 30 | namespace ChromeViews { |
| 31 | |
| 32 | class Background; |
| 33 | class Border; |
| 34 | class FocusManager; |
| 35 | class FocusTraversable; |
| 36 | class LayoutManager; |
| 37 | class RestoreFocusTask; |
| 38 | class RootView; |
| 39 | class ScrollView; |
| 40 | class ViewContainer; |
| 41 | |
| 42 | // ContextMenuController is responsible for showing the context menu for a |
| 43 | // View. To use a ContextMenuController invoke SetContextMenuController on a |
| 44 | // View. When the appropriate user gesture occurs ShowContextMenu is invoked |
| 45 | // on the ContextMenuController. |
| 46 | // |
| 47 | // Setting a ContextMenuController on a view makes the view process mouse |
| 48 | // events. |
| 49 | // |
| 50 | // It is up to subclasses that do their own mouse processing to invoke |
| 51 | // the appropriate ContextMenuController method, typically by invoking super's |
| 52 | // implementation for mouse processing. |
| 53 | // |
| 54 | class ContextMenuController { |
| 55 | public: |
| 56 | // Invoked to show the context menu for the source view. If is_mouse_gesture |
| 57 | // is true, the x/y coordinate are the location of the mouse. If |
| 58 | // is_mouse_gesture is false, this method was not invoked by a mouse gesture |
| 59 | // and x/y is the recommended location to show the menu at. |
| 60 | // |
| 61 | // x/y is in screen coordinates. |
| 62 | virtual void ShowContextMenu(View* source, |
| 63 | int x, |
| 64 | int y, |
| 65 | bool is_mouse_gesture) = 0; |
| 66 | }; |
| 67 | |
| 68 | // DragController is responsible for writing drag data for a view, as well as |
| 69 | // supplying the supported drag operations. Use DragController if you don't |
| 70 | // want to subclass. |
| 71 | |
| 72 | class DragController { |
| 73 | public: |
| 74 | // Writes the data for the drag. |
| 75 | virtual void WriteDragData(View* sender, |
| 76 | int press_x, |
| 77 | int press_y, |
| 78 | OSExchangeData* data) = 0; |
| 79 | |
| 80 | // Returns the supported drag operations (see DragDropTypes for possible |
| 81 | // values). A drag is only started if this returns a non-zero value. |
| 82 | virtual int GetDragOperations(View* sender, int x, int y) = 0; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | ///////////////////////////////////////////////////////////////////////////// |
| 87 | // |
| 88 | // View class |
| 89 | // |
| 90 | // A View is a rectangle within the ChromeViews View hierarchy. It is the |
| 91 | // base class for all Views. |
| 92 | // |
| 93 | // A View is a container of other Views (there is no such thing as a Leaf |
| 94 | // View - makes code simpler, reduces type conversion headaches, design |
| 95 | // mistakes etc) |
| 96 | // |
| 97 | // The View contains basic properties for sizing (bounds), layout (flex, |
| 98 | // orientation, etc), painting of children and event dispatch. |
| 99 | // |
| 100 | // The View also uses a simple Box Layout Manager similar to XUL's |
| 101 | // SprocketLayout system. Alternative Layout Managers implementing the |
| 102 | // LayoutManager interface can be used to lay out children if required. |
| 103 | // |
| 104 | // It is up to the subclass to implement Painting and storage of subclass - |
| 105 | // specific properties and functionality. |
| 106 | // |
| 107 | ///////////////////////////////////////////////////////////////////////////// |
| 108 | class View : public AcceleratorTarget { |
| 109 | public: |
| 110 | |
| 111 | // Used in EnumerateFloatingViews() to specify which floating view to |
| 112 | // retrieve. |
| 113 | enum FloatingViewPosition { |
| 114 | FIRST = 0, |
| 115 | NEXT, |
| 116 | PREVIOUS, |
| 117 | LAST, |
| 118 | CURRENT |
| 119 | }; |
| 120 | |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 121 | // Used in the versions of GetBounds() and x() that take a transformation |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | // parameter in order to determine whether or not to take into account the |
| 123 | // mirroring setting of the View when returning bounds positions. |
| 124 | enum PositionMirroringSettings { |
| 125 | IGNORE_MIRRORING_TRANSFORMATION = 0, |
| 126 | APPLY_MIRRORING_TRANSFORMATION |
| 127 | }; |
| 128 | |
| 129 | // The view class name. |
| 130 | static char kViewClassName[]; |
| 131 | |
| 132 | View(); |
| 133 | virtual ~View(); |
| 134 | |
| 135 | // Sizing functions |
| 136 | |
| 137 | // Get the bounds of the View, relative to the parent. Essentially, this |
| 138 | // function returns the bounds_ rectangle. |
| 139 | // |
| 140 | // This is the function subclasses should use whenever they need to obtain |
| 141 | // the bounds of one of their child views (for example, when implementing |
| 142 | // View::Layout()). |
| 143 | void GetBounds(CRect *out) const { |
| 144 | GetBounds(out, IGNORE_MIRRORING_TRANSFORMATION); |
| 145 | }; |
| 146 | |
| 147 | // Return the bounds of the View, relative to the parent. If |
| 148 | // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the |
| 149 | // bounds_ rectangle. If |settings| is APPLY_MIRRORING_SETTINGS AND the |
| 150 | // parent View is using a right-to-left UI layout, then the function returns |
| 151 | // a shifted version of the bounds_ rectangle that represents the mirrored |
| 152 | // View bounds. |
| 153 | // |
| 154 | // NOTE: in the vast majority of the cases, the mirroring implementation is |
| 155 | // transparent to the View subclasses and therefore you should use the |
| 156 | // version of GetBounds() which does not take a transformation settings |
| 157 | // parameter. |
| 158 | void GetBounds(CRect *out, PositionMirroringSettings settings) const; |
| 159 | |
| 160 | // Set the bounds in the parent's coordinate system. |
| 161 | void SetBounds(const CRect& bounds); |
| 162 | void SetBounds(int x, int y, int width, int height); |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 163 | void SetX(int x) { SetBounds(x, y(), width(), height()); } |
| 164 | void SetY(int y) { SetBounds(x(), y, width(), height()); } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 165 | |
| 166 | // Returns the left coordinate of the View, relative to the parent View, |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 167 | // which is the value of bounds_.left. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 168 | // |
| 169 | // This is the function subclasses should use whenever they need to obtain |
| 170 | // the left position of one of their child views (for example, when |
| 171 | // implementing View::Layout()). |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 172 | int x() const { |
| 173 | // This is equivalent to GetX(IGNORE_MIRRORING_TRANSFORMATION), but |
| 174 | // inlinable. |
| 175 | return bounds_.left; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | // Return the left coordinate of the View, relative to the parent. If |
| 179 | // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of |
| 180 | // bounds_.left. If |settings| is APPLY_MIRRORING_SETTINGS AND the parent |
| 181 | // View is using a right-to-left UI layout, then the function returns the |
| 182 | // mirrored value of bounds_.left. |
| 183 | // |
| 184 | // NOTE: in the vast majority of the cases, the mirroring implementation is |
| 185 | // transparent to the View subclasses and therefore you should use the |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 186 | // paremeterless version of x() when you need to get the X |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | // coordinate of a child View. |
| 188 | int GetX(PositionMirroringSettings settings) const; |
| 189 | |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 190 | int y() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 191 | return bounds_.top; |
| 192 | }; |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 193 | int width() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 194 | return bounds_.Width(); |
| 195 | }; |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 196 | int height() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 197 | return bounds_.Height(); |
| 198 | }; |
| 199 | |
| 200 | // Return this control local bounds. If include_border is true, local bounds |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 201 | // is the rectangle {0, 0, width(), height()}, otherwise, it does not |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 202 | // include the area where the border (if any) is painted. |
| 203 | void GetLocalBounds(CRect* out, bool include_border) const; |
| 204 | |
| 205 | // Get the size of the View |
| 206 | void GetSize(CSize* out) const; |
| 207 | |
| 208 | // Get the position of the View, relative to the parent. |
| 209 | // |
| 210 | // Note that if the parent uses right-to-left UI layout, then the mirrored |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 211 | // position of this View is returned. Use x()/y() if you want to ignore |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | // mirroring. |
| 213 | void GetPosition(CPoint* out) const; |
| 214 | |
| 215 | // Get the size the View would like to be, if enough space were available. |
| 216 | virtual void GetPreferredSize(CSize* out); |
| 217 | |
| 218 | // Convenience method that sizes this view to its preferred size. |
| 219 | void SizeToPreferredSize(); |
| 220 | |
| 221 | // Gets the minimum size of the view. View's implementation invokes |
| 222 | // GetPreferredSize. |
| 223 | virtual void GetMinimumSize(CSize* out); |
| 224 | |
| 225 | // Return the height necessary to display this view with the provided width. |
| 226 | // View's implementation returns the value from getPreferredSize.cy. |
| 227 | // Override if your View's preferred height depends upon the width (such |
| 228 | // as with Labels). |
| 229 | virtual int GetHeightForWidth(int w); |
| 230 | |
| 231 | // This method is invoked when this object size or position changes. |
| 232 | // The default implementation does nothing. |
| 233 | virtual void DidChangeBounds(const CRect& previous, const CRect& current); |
| 234 | |
| 235 | // Set whether the receiving view is visible. Painting is scheduled as needed |
| 236 | virtual void SetVisible(bool flag); |
| 237 | |
| 238 | // Return whether a view is visible |
| 239 | virtual bool IsVisible() const { return is_visible_; } |
| 240 | |
| 241 | // Return whether a view and its ancestors are visible. Returns true if the |
| 242 | // path from this view to the root view is visible. |
| 243 | virtual bool IsVisibleInRootView() const; |
| 244 | |
| 245 | // Set whether this view is enabled. A disabled view does not receive keyboard |
| 246 | // or mouse inputs. If flag differs from the current value, SchedulePaint is |
| 247 | // invoked. |
| 248 | virtual void SetEnabled(bool flag); |
| 249 | |
| 250 | // Returns whether the view is enabled. |
| 251 | virtual bool IsEnabled() const; |
| 252 | |
| 253 | // Set whether this view is hottracked. A disabled view cannot be hottracked. |
| 254 | // If flag differs from the current value, SchedulePaint is invoked. |
| 255 | virtual void SetHotTracked(bool flag); |
| 256 | |
| 257 | // Returns whether the view is hot-tracked. |
| 258 | virtual bool IsHotTracked() const { return false; } |
| 259 | |
| 260 | // Returns whether the view is pushed. |
| 261 | virtual bool IsPushed() const { return false; } |
| 262 | |
| 263 | // Scrolls the specified region, in this View's coordinate system, to be |
| 264 | // visible. View's implementation passes the call onto the parent View (after |
| 265 | // adjusting the coordinates). It is up to views that only show a portion of |
| 266 | // the child view, such as Viewport, to override appropriately. |
| 267 | virtual void ScrollRectToVisible(int x, int y, int width, int height); |
| 268 | |
| 269 | // Layout functions |
| 270 | |
| 271 | // Lay out the child Views (set their bounds based on sizing heuristics |
| 272 | // specific to the current Layout Manager) |
| 273 | virtual void Layout(); |
| 274 | |
| 275 | // Gets/Sets the Layout Manager used by this view to size and place its |
| 276 | // children. |
| 277 | // The LayoutManager is owned by the View and is deleted when the view is |
| 278 | // deleted, or when a new LayoutManager is installed. |
| 279 | LayoutManager* GetLayoutManager() const; |
| 280 | void SetLayoutManager(LayoutManager* layout); |
| 281 | |
| 282 | // Right-to-left UI layout functions |
| 283 | |
| 284 | // Indicates whether the UI layout for this view is right-to-left. The view |
| 285 | // has an RTL UI layout if RTL hasn't been disabled for the view and if the |
| 286 | // locale's language is an RTL language. |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 287 | bool UILayoutIsRightToLeft() const; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 288 | |
| 289 | // Enables or disables the right-to-left layout for the view. If |enable| is |
| 290 | // true, the layout will become right-to-left only if the locale's language |
| 291 | // is right-to-left. |
| 292 | // |
| 293 | // By default, right-to-left UI layout is enabled for the view and therefore |
| 294 | // this function must be called (with false as the |enable| parameter) in |
| 295 | // order to disable the right-to-left layout property for a specific instance |
| 296 | // of the view. Disabling the right-to-left UI layout is necessary in case a |
| 297 | // UI element will not appear correctly when mirrored. |
| 298 | void EnableUIMirroringForRTLLanguages(bool enable) { |
| 299 | ui_mirroring_is_enabled_for_rtl_languages_ = enable; |
| 300 | } |
| 301 | |
| 302 | // This method determines whether the ChromeCanvas object passed to |
| 303 | // View::Paint() needs to be transformed such that anything drawn on the |
| 304 | // canvas object during View::Paint() is flipped horizontally. |
| 305 | // |
| 306 | // By default, this function returns false (which is the initial value of |
| 307 | // |flip_canvas_on_paint_for_rtl_ui_|). View subclasses that need to paint on |
| 308 | // a flipped ChromeCanvas when the UI layout is right-to-left need to call |
| 309 | // EnableCanvasFlippingForRTLUI(). |
| 310 | bool FlipCanvasOnPaintForRTLUI() const { |
| 311 | return flip_canvas_on_paint_for_rtl_ui_ ? UILayoutIsRightToLeft() : false; |
| 312 | } |
| 313 | |
| 314 | // Enables or disables flipping of the ChromeCanvas during View::Paint(). |
| 315 | // Note that if canvas flipping is enabled, the canvas will be flipped only |
| 316 | // if the UI layout is right-to-left; that is, the canvas will be flipped |
| 317 | // only if UILayoutIsRightToLeft() returns true. |
| 318 | // |
| 319 | // Enabling canvas flipping is useful for leaf views that draw a bitmap that |
| 320 | // needs to be flipped horizontally when the UI layout is right-to-left |
| 321 | // (ChromeViews::Button, for example). This method is helpful for such |
| 322 | // classes because their drawing logic stays the same and they can become |
| 323 | // agnostic to the UI directionality. |
| 324 | void EnableCanvasFlippingForRTLUI(bool enable) { |
| 325 | flip_canvas_on_paint_for_rtl_ui_ = enable; |
| 326 | } |
| 327 | |
| 328 | // Returns the mirrored X position for the view, relative to the parent. If |
| 329 | // the parent view is not mirrored, this function returns bound_.left. |
| 330 | // |
| 331 | // UI mirroring is transparent to most View subclasses and therefore there is |
| 332 | // no need to call this routine from anywhere within your subclass |
| 333 | // implementation. |
[email protected] | 6332998 | 2008-10-10 21:56:57 | [diff] [blame^] | 334 | int MirroredX() const; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | |
| 336 | // Given a rectangle specified in this View's coordinate system, the function |
| 337 | // computes the 'left' value for the mirrored rectangle within this View. If |
| 338 | // the View's UI layout is not right-to-left, then bounds.x() is returned. |
| 339 | // |
| 340 | // UI mirroring is transparent to most View subclasses and therefore there is |
| 341 | // no need to call this routine from anywhere within your subclass |
| 342 | // implementation. |
| 343 | int MirroredLeftPointForRect(const gfx::Rect& rect) const; |
| 344 | |
| 345 | // Given the X coordinate of a point inside the View, this function returns |
| 346 | // the mirrored X coordinate of the point if the View's UI layout is |
| 347 | // right-to-left. If the layout is left-to-right, the same X coordinate is |
| 348 | // returned. |
| 349 | // |
| 350 | // Following are a few examples of the values returned by this function for |
| 351 | // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: |
| 352 | // |
| 353 | // MirroredXCoordinateInsideView(0) -> 100 |
| 354 | // MirroredXCoordinateInsideView(20) -> 80 |
| 355 | // MirroredXCoordinateInsideView(99) -> 1 |
| 356 | int MirroredXCoordinateInsideView(int x) const { |
[email protected] | 6f3bb6c | 2008-09-17 22:25:33 | [diff] [blame] | 357 | return UILayoutIsRightToLeft() ? width() - x : x; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | // Painting functions |
| 361 | |
| 362 | // Mark the specified rectangle as dirty (needing repaint). If |urgent| is |
| 363 | // true, the view will be repainted when the current event processing is |
| 364 | // done. Otherwise, painting will take place as soon as possible. |
| 365 | virtual void SchedulePaint(const CRect& r, bool urgent); |
| 366 | |
| 367 | // Mark the entire View's bounds as dirty. Painting will occur as soon as |
| 368 | // possible. |
| 369 | virtual void SchedulePaint(); |
| 370 | |
| 371 | // Convenience to schedule a paint given some ints. Painting will occur as |
| 372 | // soon as possible. |
| 373 | virtual void SchedulePaint(int x, int y, int w, int h); |
| 374 | |
| 375 | // Paint the receiving view. g is prepared such as it is in |
| 376 | // receiver's coordinate system. g's state is restored after this |
| 377 | // call so your implementation can change the graphics configuration |
| 378 | // |
| 379 | // Default implementation paints the background if it is defined |
| 380 | // |
| 381 | // Override this method when implementing a new control. |
| 382 | virtual void Paint(ChromeCanvas* canvas); |
| 383 | |
| 384 | // Paint the background if any. This method is called by Paint() and |
| 385 | // should rarely be invoked directly. |
| 386 | virtual void PaintBackground(ChromeCanvas* canvas); |
| 387 | |
| 388 | // Paint the border if any. This method is called by Paint() and |
| 389 | // should rarely be invoked directly. |
| 390 | virtual void PaintBorder(ChromeCanvas* canvas); |
| 391 | |
| 392 | // Paints the focus border (only if the view has the focus). |
| 393 | // This method is called by Paint() and should rarely be invoked directly. |
| 394 | // The default implementation paints a gray border around the view. Override |
| 395 | // it for custom focus effects. |
| 396 | virtual void PaintFocusBorder(ChromeCanvas* canvas); |
| 397 | |
| 398 | // Paint this View immediately. |
| 399 | virtual void PaintNow(); |
| 400 | |
| 401 | // Paint a view without attaching it to this view hierarchy. |
| 402 | // Any view can be painted that way. |
| 403 | // This method set bounds, calls layout and handles clipping properly. The |
| 404 | // provided view can be attached to a parent. The parent will be saved and |
| 405 | // restored. (x, y, width, height) define the floating view bounds |
| 406 | void PaintFloatingView(ChromeCanvas* canvas, View* view, |
| 407 | int x, int y, int w, int h); |
| 408 | |
| 409 | // Tree functions |
| 410 | |
| 411 | // Add a child View. |
| 412 | void AddChildView(View* v); |
| 413 | |
| 414 | // Adds a child View at the specified position. |
| 415 | void AddChildView(int index, View* v); |
| 416 | |
| 417 | // Get the child View at the specified index. |
| 418 | View* GetChildViewAt(int index) const; |
| 419 | |
| 420 | // Remove a child view from this view. v's parent will change to NULL |
| 421 | void RemoveChildView(View *v); |
| 422 | |
| 423 | // Remove all child view from this view. If |delete_views| is true, the views |
| 424 | // are deleted, unless marked as not parent owned. |
| 425 | void RemoveAllChildViews(bool delete_views); |
| 426 | |
| 427 | // Get the number of child Views. |
| 428 | int GetChildViewCount() const; |
| 429 | |
| 430 | // Get the child View at the specified point. |
| 431 | virtual View* GetViewForPoint(const CPoint& point); |
| 432 | |
| 433 | // Get the containing ViewContainer |
| 434 | virtual ViewContainer* GetViewContainer() const; |
| 435 | |
| 436 | // Get the containing RootView |
| 437 | virtual RootView* GetRootView(); |
| 438 | |
| 439 | // Get the parent View |
| 440 | View* GetParent() const { return parent_; } |
| 441 | |
| 442 | // Returns the index of the specified |view| in this view's children, or -1 |
| 443 | // if the specified view is not a child of this view. |
| 444 | int GetChildIndex(View* v) const; |
| 445 | |
| 446 | // Returns true if the specified view is a direct or indirect child of this |
| 447 | // view. |
| 448 | bool IsParentOf(View* v) const; |
| 449 | |
| 450 | // Recursively descends the view tree starting at this view, and returns |
| 451 | // the first child that it encounters that has the given ID. |
| 452 | // Returns NULL if no matching child view is found. |
| 453 | virtual View* GetViewByID(int id) const; |
| 454 | |
| 455 | // Sets and gets the ID for this view. ID should be unique within the subtree |
| 456 | // that you intend to search for it. 0 is the default ID for views. |
| 457 | void SetID(int id); |
| 458 | int GetID() const; |
| 459 | |
| 460 | // A group id is used to tag views which are part of the same logical group. |
| 461 | // Focus can be moved between views with the same group using the arrow keys. |
| 462 | // Groups are currently used to implement radio button mutual exclusion. |
| 463 | void SetGroup(int gid); |
| 464 | int GetGroup() const; |
| 465 | |
| 466 | // If this returns true, the views from the same group can each be focused |
| 467 | // when moving focus with the Tab/Shift-Tab key. If this returns false, |
| 468 | // only the selected view from the group (obtained with |
| 469 | // GetSelectedViewForGroup()) is focused. |
| 470 | virtual bool IsGroupFocusTraversable() const { return true; } |
| 471 | |
| 472 | // Fills the provided vector with all the available views which belong to the |
| 473 | // provided group. |
| 474 | void GetViewsWithGroup(int group_id, std::vector<View*>* out); |
| 475 | |
| 476 | // Return the View that is currently selected in the specified group. |
| 477 | // The default implementation simply returns the first View found for that |
| 478 | // group. |
| 479 | virtual View* GetSelectedViewForGroup(int group_id); |
| 480 | |
| 481 | // Focus support |
| 482 | // |
| 483 | // Returns the view that should be selected next when pressing Tab. |
| 484 | View* GetNextFocusableView(); |
| 485 | |
| 486 | // Returns the view that should be selected next when pressing Shift-Tab. |
| 487 | View* GetPreviousFocusableView(); |
| 488 | |
| 489 | // Sets the component that should be selected next when pressing Tab, and |
| 490 | // makes the current view the precedent view of the specified one. |
| 491 | // Note that by default views are linked in the order they have been added to |
| 492 | // their container. Use this method if you want to modify the order. |
| 493 | // IMPORTANT NOTE: loops in the focus hierarchy are not supported. |
| 494 | void SetNextFocusableView(View* view); |
| 495 | |
| 496 | // Return whether this view can accept the focus. |
| 497 | virtual bool IsFocusable() const; |
| 498 | |
| 499 | // Sets whether this view can accept the focus. |
| 500 | // Note that this is false by default so that a view used as a container does |
| 501 | // not get the focus. |
| 502 | virtual void SetFocusable(bool focusable); |
| 503 | |
| 504 | // Convenience method to retrieve the FocusManager associated with the |
| 505 | // container window that contains this view. This can return NULL if this |
| 506 | // view is not part of a view hierarchy with a ViewContainer. |
| 507 | virtual FocusManager* GetFocusManager(); |
| 508 | |
| 509 | // Sets a keyboard accelerator for that view. When the user presses the |
| 510 | // accelerator key combination, the AcceleratorPressed method is invoked. |
| 511 | // Note that you can set multiple accelerators for a view by invoking this |
| 512 | // method several times. |
| 513 | virtual void AddAccelerator(const Accelerator& accelerator); |
| 514 | |
| 515 | // Removes all the keyboard accelerators for this view. |
| 516 | virtual void ResetAccelerators(); |
| 517 | |
| 518 | // Called when a keyboard accelerator is pressed. |
| 519 | // Derived classes should implement desired behavior and return true if they |
| 520 | // handled the accelerator. |
| 521 | virtual bool AcceleratorPressed(const Accelerator& accelerator) { |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | // Called on a view (if it is has focus) before an Accelerator is processed. |
| 526 | // Views that want to override an accelerator should override this method to |
| 527 | // perform the required action and return true, to indicate that the |
| 528 | // accelerator should not be processed any further. |
| 529 | virtual bool OverrideAccelerator(const Accelerator& accelerator) { |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | // Returns whether this view currently has the focus. |
| 534 | virtual bool HasFocus(); |
| 535 | |
| 536 | // Accessibility support |
| 537 | // TODO(klink): Move all this out to a AccessibleInfo wrapper class. |
| 538 | // |
| 539 | // Returns the MSAA default action of the current view. The string returned |
| 540 | // describes the default action that will occur when executing |
| 541 | // IAccessible::DoDefaultAction. For instance, default action of a button is |
| 542 | // 'Press'. Sets the input string appropriately, and returns true if |
| 543 | // successful. |
| 544 | virtual bool GetAccessibleDefaultAction(std::wstring* action) { |
| 545 | return false; |
| 546 | } |
| 547 | |
| 548 | // Returns a string containing the mnemonic, or the keyboard shortcut, for a |
| 549 | // given control. Sets the input string appropriately, and returns true if |
| 550 | // successful. |
| 551 | virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut) { |
| 552 | return false; |
| 553 | } |
| 554 | |
| 555 | // Returns a brief, identifying string, containing a unique, readable name of |
| 556 | // a given control. Sets the input string appropriately, and returns true if |
| 557 | // successful. |
| 558 | virtual bool GetAccessibleName(std::wstring* name) { return false; } |
| 559 | |
| 560 | // Returns the MSAA role of the current view. The role is what assistive |
| 561 | // technologies (ATs) use to determine what behavior to expect from a given |
| 562 | // control. Sets the input VARIANT appropriately, and returns true if |
| 563 | // successful. |
| 564 | virtual bool GetAccessibleRole(VARIANT* role) { return false; } |
| 565 | |
| 566 | // Returns the MSAA state of the current view. Sets the input VARIANT |
| 567 | // appropriately, and returns true if a change was performed successfully. |
| 568 | virtual bool GetAccessibleState(VARIANT* state) { return false; } |
| 569 | |
| 570 | // Assigns a keyboard shortcut string description to the given control. Needed |
| 571 | // as a View does not know which shortcut will be associated with it until it |
| 572 | // is created to be a certain type. |
| 573 | virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {} |
| 574 | |
| 575 | // Assigns a string name to the given control. Needed as a View does not know |
| 576 | // which name will be associated with it until it is created to be a |
| 577 | // certain type. |
| 578 | virtual void SetAccessibleName(const std::wstring& name) {} |
| 579 | |
| 580 | // Returns an instance of a wrapper class implementing the (platform-specific) |
| 581 | // accessibility interface for a given View. If one exists, it will be |
| 582 | // re-used, otherwise a new instance will be created. |
| 583 | AccessibleWrapper* GetAccessibleWrapper(); |
| 584 | |
| 585 | // Accessor used to determine if a child view (leaf) has accessibility focus. |
| 586 | // Returns NULL if there are no children, or if none of the children has |
| 587 | // accessibility focus. |
| 588 | virtual ChromeViews::View* GetAccFocusedChildView() { return NULL; } |
| 589 | |
| 590 | // Floating views |
| 591 | // |
| 592 | // A floating view is a view that is used to paint a cell within a parent view |
| 593 | // Floating Views are painted using PaintFloatingView() above. |
| 594 | // |
| 595 | // Floating views can also be lazily created and attached to the view |
| 596 | // hierarchy to process events. To make this possible, each view is given an |
| 597 | // opportunity to create and attach a floating view right before an mouse |
| 598 | // event is processed. |
| 599 | |
| 600 | // Retrieves the id for the floating view at the specified coordinates if any. |
| 601 | // Derived classes that use floating views should implement this method and |
| 602 | // return true if a view has been found and its id set in |id|. |
| 603 | virtual bool GetFloatingViewIDForPoint(int x, int y, int* id); |
| 604 | |
| 605 | // Retrieves the ID of the floating view at the specified |position| and sets |
| 606 | // it in |id|. |
| 607 | // For positions NEXT and PREVIOUS, the specified |starting_id| is used as |
| 608 | // the origin, it is ignored for FIRST and LAST. |
| 609 | // Returns true if an ID was found, false otherwise. |
| 610 | // For CURRENT, the |starting_id| should be set in |id| and true returned if |
| 611 | // the |starting_id| is a valid floating view id. |
| 612 | // Derived classes that use floating views should implement this method and |
| 613 | // return a unique ID for each floating view. |
| 614 | // The default implementation always returns false. |
| 615 | virtual bool EnumerateFloatingViews(FloatingViewPosition position, |
| 616 | int starting_id, |
| 617 | int* id); |
| 618 | |
| 619 | // Creates and attaches the floating view with the specified |id| to this view |
| 620 | // hierarchy and returns it. |
| 621 | // Derived classes that use floating views should implement this method. |
| 622 | // |
| 623 | // NOTE: subclasses implementing this should return NULL if passed an invalid |
| 624 | // id. An invalid ID may be passed in by the focus manager when attempting |
| 625 | // to restore focus. |
| 626 | virtual View* ValidateFloatingViewForID(int id); |
| 627 | |
| 628 | // Whether the focus should automatically be restored to the last focused |
| 629 | // view. Default implementation returns true. |
| 630 | // Derived classes that want to restore focus themselves should override this |
| 631 | // method and return false. |
| 632 | virtual bool ShouldRestoreFloatingViewFocus(); |
| 633 | |
| 634 | // Attach a floating view to the receiving view. The view is inserted |
| 635 | // in the child view list and will behave like a normal view. |id| is the |
| 636 | // floating view id for that view. |
| 637 | void AttachFloatingView(View* v, int id); |
| 638 | |
| 639 | // Return whether a view already has a floating view which bounds intersects |
| 640 | // the provided point. |
| 641 | // |
| 642 | // If the View uses right-to-left UI layout, then the given point is checked |
| 643 | // against the mirrored position of each floating View. |
| 644 | bool HasFloatingViewForPoint(int x, int y); |
| 645 | |
| 646 | // Detach and delete all floating views. Call this method when your model |
| 647 | // or layout changes. |
| 648 | void DetachAllFloatingViews(); |
| 649 | |
| 650 | // Returns the view with the specified |id|, by calling |
| 651 | // ValidateFloatingViewForID if that view has not yet been attached. |
| 652 | virtual View* RetrieveFloatingViewForID(int id); |
| 653 | |
| 654 | // Restores the focus to the previously selected floating view. |
| 655 | virtual void RestoreFloatingViewFocus(); |
| 656 | |
| 657 | // Goes up the parent hierarchy of this view and returns the first floating |
| 658 | // view found. Returns NULL if none were found. |
| 659 | View* RetrieveFloatingViewParent(); |
| 660 | |
| 661 | // Utility functions |
| 662 | |
| 663 | // Note that the utility coordinate conversions functions always operate on |
| 664 | // the mirrored position of the child Views if the parent View uses a |
| 665 | // right-to-left UI layout. |
| 666 | |
| 667 | // Convert a point from source coordinate system to dst coordinate system. |
| 668 | // |
| 669 | // source is a parent or a child of dst, directly or transitively. |
| 670 | // If source and dst are not in the same View hierarchy, the result is |
| 671 | // undefined. |
| 672 | // Source can be NULL in which case it means the screen coordinate system |
| 673 | static void ConvertPointToView(View* src, |
| 674 | View* dst, |
| 675 | gfx::Point* point); |
| 676 | // WARNING: DEPRECATED. Will be removed once everything is converted to |
| 677 | // gfx::Point. Don't add code that use this overload. |
| 678 | static void ConvertPointToView(View* src, |
| 679 | View* dst, |
| 680 | CPoint* point); |
| 681 | |
| 682 | // Convert a point from the coordinate system of a View to that of the |
| 683 | // ViewContainer. This is useful for example when sizing HWND children |
| 684 | // of the ViewContainer that don't know about the View hierarchy and need |
| 685 | // to be placed relative to the ViewContainer that is their parent. |
| 686 | static void ConvertPointToViewContainer(View* src, CPoint* point); |
| 687 | |
| 688 | // Convert a point from a view ViewContainer to a View dest |
| 689 | static void ConvertPointFromViewContainer(View *dest, CPoint *p); |
| 690 | |
| 691 | // Convert a point from the coordinate system of a View to that of the |
| 692 | // screen. This is useful for example when placing popup windows. |
| 693 | static void ConvertPointToScreen(View* src, CPoint* point); |
| 694 | |
| 695 | // Event Handlers |
| 696 | |
| 697 | // This method is invoked when the user clicks on this view. |
| 698 | // The provided event is in the receiver's coordinate system. |
| 699 | // |
| 700 | // Return true if you processed the event and want to receive subsequent |
| 701 | // MouseDraggged and MouseReleased events. This also stops the event from |
| 702 | // bubbling. If you return false, the event will bubble through parent |
| 703 | // views. |
| 704 | // |
| 705 | // If you remove yourself from the tree while processing this, event bubbling |
| 706 | // stops as if you returned true, but you will not receive future events. |
| 707 | // The return value is ignored in this case. |
| 708 | // |
| 709 | // Default implementation returns true if a ContextMenuController has been |
| 710 | // set, false otherwise. Override as needed. |
| 711 | // |
| 712 | virtual bool OnMousePressed(const MouseEvent& event); |
| 713 | |
| 714 | // This method is invoked when the user clicked on this control. |
| 715 | // and is still moving the mouse with a button pressed. |
| 716 | // The provided event is in the receiver's coordinate system. |
| 717 | // |
| 718 | // Return true if you processed the event and want to receive |
| 719 | // subsequent MouseDragged and MouseReleased events. |
| 720 | // |
| 721 | // Default implementation returns true if a ContextMenuController has been |
| 722 | // set, false otherwise. Override as needed. |
| 723 | // |
| 724 | virtual bool OnMouseDragged(const MouseEvent& event); |
| 725 | |
| 726 | // This method is invoked when the user releases the mouse |
| 727 | // button. The event is in the receiver's coordinate system. |
| 728 | // |
| 729 | // If canceled is true it indicates the mouse press/drag was canceled by a |
| 730 | // system/user gesture. |
| 731 | // |
| 732 | // Default implementation notifies the ContextMenuController is appropriate. |
| 733 | // Subclasses that wish to honor the ContextMenuController should invoke |
| 734 | // super. |
| 735 | virtual void OnMouseReleased(const MouseEvent& event, bool canceled); |
| 736 | |
| 737 | // This method is invoked when the mouse is above this control |
| 738 | // The event is in the receiver's coordinate system. |
| 739 | // |
| 740 | // Default implementation does nothing. Override as needed. |
| 741 | virtual void OnMouseMoved(const MouseEvent& e); |
| 742 | |
| 743 | // This method is invoked when the mouse enters this control. |
| 744 | // |
| 745 | // Default implementation does nothing. Override as needed. |
| 746 | virtual void OnMouseEntered(const MouseEvent& event); |
| 747 | |
| 748 | // This method is invoked when the mouse exits this control |
| 749 | // The provided event location is always (0, 0) |
| 750 | // Default implementation does nothing. Override as needed. |
| 751 | virtual void OnMouseExited(const MouseEvent& event); |
| 752 | |
| 753 | // Set the MouseHandler for a drag session. |
| 754 | // |
| 755 | // A drag session is a stream of mouse events starting |
| 756 | // with a MousePressed event, followed by several MouseDragged |
| 757 | // events and finishing with a MouseReleased event. |
| 758 | // |
| 759 | // This method should be only invoked while processing a |
| 760 | // MouseDragged or MouseReleased event. |
| 761 | // |
| 762 | // All further mouse dragged and mouse up events will be sent |
| 763 | // the MouseHandler, even if it is reparented to another window. |
| 764 | // |
| 765 | // The MouseHandler is automatically cleared when the control |
| 766 | // comes back from processing the MouseReleased event. |
| 767 | // |
| 768 | // Note: if the mouse handler is no longer connected to a |
| 769 | // view hierarchy, events won't be sent. |
| 770 | // |
| 771 | virtual void SetMouseHandler(View* new_mouse_handler); |
| 772 | |
| 773 | // Request the keyboard focus. The receiving view will become the |
| 774 | // focused view. |
| 775 | virtual void RequestFocus(); |
| 776 | |
| 777 | // Invoked when a view is about to gain focus |
| 778 | virtual void WillGainFocus(); |
| 779 | |
| 780 | // Invoked when a view just gained focus. |
| 781 | virtual void DidGainFocus(); |
| 782 | |
| 783 | // Invoked when a view is about lose focus |
| 784 | virtual void WillLoseFocus(); |
| 785 | |
| 786 | // Invoked when a view is about to be requested for focus due to the focus |
| 787 | // traversal. Reverse is this request was generated going backward |
| 788 | // (Shift-Tab). |
| 789 | virtual void AboutToRequestFocusFromTabTraversal(bool reverse) { } |
| 790 | |
| 791 | // Invoked when a key is pressed or released. |
| 792 | // Subclasser should return true if the event has been processed and false |
| 793 | // otherwise. If the event has not been processed, the parent will be given a |
| 794 | // chance. |
| 795 | virtual bool OnKeyPressed(const KeyEvent& e); |
| 796 | virtual bool OnKeyReleased(const KeyEvent& e); |
| 797 | |
| 798 | // Whether the view wants to receive Tab and Shift-Tab key events. |
| 799 | // If false, Tab and Shift-Tabs key events are used for focus traversal and |
| 800 | // are not sent to the view. If true, the events are sent to the view and not |
| 801 | // used for focus traversal. |
| 802 | // This implementation returns false (so that by default views handle nicely |
| 803 | // the keyboard focus traversal). |
| 804 | virtual bool CanProcessTabKeyEvents(); |
| 805 | |
| 806 | // Invoked when the user uses the mousewheel. Implementors should return true |
| 807 | // if the event has been processed and false otherwise. This message is sent |
| 808 | // if the view is focused. If the event has not been processed, the parent |
| 809 | // will be given a chance. |
| 810 | virtual bool OnMouseWheel(const MouseWheelEvent& e); |
| 811 | |
| 812 | // Drag and drop functions. |
| 813 | |
| 814 | // Set/get the DragController. See description of DragController for more |
| 815 | // information. |
| 816 | void SetDragController(DragController* drag_controller); |
| 817 | DragController* GetDragController(); |
| 818 | |
| 819 | // During a drag and drop session when the mouse moves the view under the |
| 820 | // mouse is queried to see if it should be a target for the drag and drop |
| 821 | // session. A view indicates it is a valid target by returning true from |
| 822 | // CanDrop. If a view returns true from CanDrop, |
| 823 | // OnDragEntered is sent to the view when the mouse first enters the view, |
| 824 | // as the mouse moves around within the view OnDragUpdated is invoked. |
| 825 | // If the user releases the mouse over the view and OnDragUpdated returns a |
| 826 | // valid drop, then OnPerformDrop is invoked. If the mouse moves outside the |
| 827 | // view or over another view that wants the drag, OnDragExited is invoked. |
| 828 | // |
| 829 | // Similar to mouse events, the deepest view under the mouse is first checked |
| 830 | // if it supports the drop (Drop). If the deepest view under |
| 831 | // the mouse does not support the drop, the ancestors are walked until one |
| 832 | // is found that supports the drop. |
| 833 | |
| 834 | // A view that supports drag and drop must override this and return true if |
| 835 | // data contains a type that may be dropped on this view. |
| 836 | virtual bool CanDrop(const OSExchangeData& data); |
| 837 | |
| 838 | // OnDragEntered is invoked when the mouse enters this view during a drag and |
| 839 | // drop session and CanDrop returns true. This is immediately |
| 840 | // followed by an invocation of OnDragUpdated, and eventually one of |
| 841 | // OnDragExited or OnPerformDrop. |
| 842 | virtual void OnDragEntered(const DropTargetEvent& event); |
| 843 | |
| 844 | // Invoked during a drag and drop session while the mouse is over the view. |
| 845 | // This should return a bitmask of the DragDropTypes::DragOperation supported |
| 846 | // based on the location of the event. Return 0 to indicate the drop should |
| 847 | // not be accepted. |
| 848 | virtual int OnDragUpdated(const DropTargetEvent& event); |
| 849 | |
| 850 | // Invoked during a drag and drop session when the mouse exits the views, or |
| 851 | // when the drag session was canceled and the mouse was over the view. |
| 852 | virtual void OnDragExited(); |
| 853 | |
| 854 | // Invoked during a drag and drop session when OnDragUpdated returns a valid |
| 855 | // operation and the user release the mouse. |
| 856 | virtual int OnPerformDrop(const DropTargetEvent& event); |
| 857 | |
| 858 | // Returns true if the mouse was dragged enough to start a drag operation. |
| 859 | // delta_x and y are the distance the mouse was dragged. |
| 860 | static bool ExceededDragThreshold(int delta_x, int delta_y); |
| 861 | |
| 862 | // This method is the main entry point to process paint for this |
| 863 | // view and its children. This method is called by the painting |
| 864 | // system. You should call this only if you want to draw a sub tree |
| 865 | // inside a custom graphics. |
| 866 | // To customize painting override either the Paint or PaintChildren method, |
| 867 | // not this one. |
| 868 | virtual void ProcessPaint(ChromeCanvas* canvas); |
| 869 | |
| 870 | // Paint the View's child Views, in reverse order. |
| 871 | virtual void PaintChildren(ChromeCanvas* canvas); |
| 872 | |
| 873 | // Sets the ContextMenuController. Setting this to non-null makes the View |
| 874 | // process mouse events. |
| 875 | void SetContextMenuController(ContextMenuController* menu_controller); |
| 876 | ContextMenuController* GetContextMenuController() { |
| 877 | return context_menu_controller_; |
| 878 | } |
| 879 | |
| 880 | // Set the background. The background is owned by the view after this call. |
| 881 | virtual void SetBackground(Background* b); |
| 882 | |
| 883 | // Return the background currently in use or NULL. |
| 884 | virtual const Background* GetBackground() const; |
| 885 | |
| 886 | // Set the border. The border is owned by the view after this call. |
| 887 | virtual void SetBorder(Border* b); |
| 888 | |
| 889 | // Return the border currently in use or NULL. |
| 890 | virtual const Border* GetBorder() const; |
| 891 | |
| 892 | // Returns the insets of the current border. If there is no border an empty |
| 893 | // insets is returned. |
| 894 | gfx::Insets GetInsets() const; |
| 895 | |
| 896 | // Return the cursor that should be used for this view or NULL if |
| 897 | // the default cursor should be used. The provided point is in the |
| 898 | // receiver's coordinate system. |
| 899 | virtual HCURSOR GetCursorForPoint(Event::EventType event_type, int x, int y); |
| 900 | |
| 901 | // Convenience to test whether a point is within this view's bounds |
| 902 | virtual bool HitTest(const CPoint &l) const; |
| 903 | |
| 904 | // Gets the tooltip for this View. If the View does not have a tooltip, |
| 905 | // return false. If the View does have a tooltip, copy the tooltip into |
| 906 | // the supplied string and return true. |
| 907 | // Any time the tooltip text that a View is displaying changes, it must |
| 908 | // invoke TooltipTextChanged. |
| 909 | // The x/y provide the coordinates of the mouse (relative to this view). |
| 910 | virtual bool GetTooltipText(int x, int y, std::wstring* tooltip); |
| 911 | |
| 912 | // Returns the location (relative to this View) for the text on the tooltip |
| 913 | // to display. If false is returned (the default), the tooltip is placed at |
| 914 | // a default position. |
| 915 | virtual bool GetTooltipTextOrigin(int x, int y, CPoint* loc); |
| 916 | |
| 917 | // Set whether this view is owned by its parent. A view that is owned by its |
| 918 | // parent is automatically deleted when the parent is deleted. The default is |
| 919 | // true. Set to false if the view is owned by another object and should not |
| 920 | // be deleted by its parent. |
| 921 | void SetParentOwned(bool f); |
| 922 | |
| 923 | // Return whether a view is owned by its parent. See SetParentOwned() |
| 924 | bool IsParentOwned() const; |
| 925 | |
| 926 | // Return the receiving view's class name. A view class is a string which |
| 927 | // uniquely identifies the view class. It is intended to be used as a way to |
| 928 | // find out during run time if a view can be safely casted to a specific view |
| 929 | // subclass. The default implementation returns kViewClassName. |
| 930 | virtual std::string GetClassName() const; |
| 931 | |
| 932 | // Returns the visible bounds of the receiver in the receivers coordinate |
| 933 | // system. |
| 934 | // |
| 935 | // When traversing the View hierarchy in order to compute the bounds, the |
| 936 | // function takes into account the mirroring setting for each View and |
| 937 | // therefore it will return the mirrored version of the visible bounds if |
| 938 | // need be. |
| 939 | gfx::Rect GetVisibleBounds(); |
| 940 | |
| 941 | // Subclasses that contain traversable children that are not directly |
| 942 | // accessible through the children hierarchy should return the associated |
| 943 | // FocusTraversable for the focus traversal to work properly. |
| 944 | virtual FocusTraversable* GetFocusTraversable() { return NULL; } |
| 945 | |
| 946 | #ifndef NDEBUG |
| 947 | // Debug method that logs the view hierarchy to the output. |
| 948 | void PrintViewHierarchy(); |
| 949 | |
| 950 | // Debug method that logs the focus traversal hierarchy to the output. |
| 951 | void PrintFocusHierarchy(); |
| 952 | #endif |
| 953 | |
| 954 | // The following methods are used by ScrollView to determine the amount |
| 955 | // to scroll relative to the visible bounds of the view. For example, a |
| 956 | // return value of 10 indicates the scrollview should scroll 10 pixels in |
| 957 | // the appropriate direction. |
| 958 | // |
| 959 | // Each method takes the following parameters: |
| 960 | // |
| 961 | // is_horizontal: if true, scrolling is along the horizontal axis, otherwise |
| 962 | // the vertical axis. |
| 963 | // is_positive: if true, scrolling is by a positive amount. Along the |
| 964 | // vertical axis scrolling by a positive amount equates to |
| 965 | // scrolling down. |
| 966 | // |
| 967 | // The return value should always be positive and gives the number of pixels |
| 968 | // to scroll. ScrollView interprets a return value of 0 (or negative) |
| 969 | // to scroll by a default amount. |
| 970 | // |
| 971 | // See VariableRowHeightScrollHelper and FixedRowHeightScrollHelper for |
| 972 | // implementations of common cases. |
| 973 | virtual int GetPageScrollIncrement(ScrollView* scroll_view, |
| 974 | bool is_horizontal, bool is_positive); |
| 975 | virtual int GetLineScrollIncrement(ScrollView* scroll_view, |
| 976 | bool is_horizontal, bool is_positive); |
| 977 | |
| 978 | protected: |
[email protected] | 82739cf | 2008-09-16 00:37:56 | [diff] [blame] | 979 | // TODO(beng): these members should NOT be protected per style guide. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 980 | // This View's bounds in the parent coordinate system. |
| 981 | CRect bounds_; |
| 982 | |
| 983 | // The id of this View. Used to find this View. |
| 984 | int id_; |
| 985 | |
| 986 | // The group of this view. Some view subclasses use this id to find other |
| 987 | // views of the same group. For example radio button uses this information |
| 988 | // to find other radio buttons. |
| 989 | int group_; |
| 990 | |
| 991 | #ifndef NDEBUG |
| 992 | // Returns true if the View is currently processing a paint. |
| 993 | virtual bool IsProcessingPaint() const; |
| 994 | #endif |
| 995 | |
[email protected] | 82739cf | 2008-09-16 00:37:56 | [diff] [blame] | 996 | // Called by HitTest to see if this View has a custom hit test mask. If the |
| 997 | // return value is true, GetHitTestMask will be called to obtain the mask. |
| 998 | // Default value is false, in which case the View will hit-test against its |
| 999 | // bounds. |
| 1000 | virtual bool HasHitTestMask() const; |
| 1001 | |
| 1002 | // Called by HitTest to retrieve a mask for hit-testing against. Subclasses |
| 1003 | // override to provide custom shaped hit test regions. |
| 1004 | virtual void GetHitTestMask(gfx::Path* mask) const; |
| 1005 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1006 | // This method is invoked when the tree changes. |
| 1007 | // |
| 1008 | // When a view is removed, it is invoked for all children and grand |
| 1009 | // children. For each of these views, a notification is sent to the |
| 1010 | // view and all parents. |
| 1011 | // |
| 1012 | // When a view is added, a notification is sent to the view, all its |
| 1013 | // parents, and all its children (and grand children) |
| 1014 | // |
| 1015 | // Default implementation does nothing. Override to perform operations |
| 1016 | // required when a view is added or removed from a view hierarchy |
| 1017 | // |
| 1018 | // parent is the new or old parent. Child is the view being added or |
| 1019 | // removed. |
| 1020 | // |
| 1021 | virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
| 1022 | |
| 1023 | // When SetVisible() changes the visibility of a view, this method is |
| 1024 | // invoked for that view as well as all the children recursively. |
| 1025 | virtual void VisibilityChanged(View* starting_from, bool is_visible); |
| 1026 | |
| 1027 | // Views must invoke this when the tooltip text they are to display changes. |
| 1028 | void TooltipTextChanged(); |
| 1029 | |
| 1030 | // Actual implementation of GetViewForPoint. |
| 1031 | virtual View* GetViewForPoint(const CPoint& point, bool can_create_floating); |
| 1032 | |
| 1033 | // Sets whether this view wants notification when its visible bounds relative |
| 1034 | // to the root view changes. If true, this view is notified any time the |
| 1035 | // origin of one its ancestors changes, or the portion of the bounds not |
| 1036 | // obscured by ancestors changes. The default is false. |
| 1037 | void SetNotifyWhenVisibleBoundsInRootChanges(bool value); |
| 1038 | bool GetNotifyWhenVisibleBoundsInRootChanges(); |
| 1039 | |
| 1040 | // Notification that this views visible bounds, relative to the RootView |
| 1041 | // has changed. The visible bounds corresponds to the region of the |
| 1042 | // view not obscured by other ancestors. |
| 1043 | virtual void VisibleBoundsInRootChanged() {} |
| 1044 | |
| 1045 | // Sets the keyboard focus to this View. The correct way to set the focus is |
| 1046 | // to call RequestFocus() on the view. This method is called when the focus is |
| 1047 | // set and gives an opportunity to subclasses to perform any extra focus steps |
| 1048 | // (for example native component set the native focus on their native |
| 1049 | // component). The default behavior is to set the native focus on the root |
| 1050 | // view container, which is what is appropriate for views that have no native |
| 1051 | // window associated with them (so the root view gets the keyboard messages). |
| 1052 | virtual void Focus(); |
| 1053 | |
| 1054 | // Heavyweight views (views that hold a native control) should return the |
| 1055 | // window for that control. |
| 1056 | virtual HWND GetNativeControlHWND() { return NULL; } |
| 1057 | |
| 1058 | // Invoked when a key is pressed before the key event is processed by the |
| 1059 | // focus manager for accelerators. This gives a chance to the view to |
| 1060 | // override an accelerator. Subclasser should return false if they want to |
| 1061 | // process the key event and not have it translated to an accelerator (if |
| 1062 | // any). In that case, OnKeyPressed will subsequently be invoked for that |
| 1063 | // event. |
| 1064 | virtual bool ShouldLookupAccelerators(const KeyEvent& e) { return true; } |
| 1065 | |
| 1066 | // A convenience method for derived classes which have floating views with IDs |
| 1067 | // that are consecutive numbers in an interval [|low_bound|, |high_bound|[. |
| 1068 | // They can call this method in their EnumerateFloatingViews implementation. |
| 1069 | // If |ascending_order| is true, the first id is |low_bound|, the next after |
| 1070 | // id n is n + 1, and so on. If |ascending_order| is false, the order is |
| 1071 | // reversed, first id is |high_bound|, the next id after id n is n -1... |
| 1072 | static bool EnumerateFloatingViewsForInterval(int low_bound, int high_bound, |
| 1073 | bool ascending_order, |
| 1074 | FloatingViewPosition position, |
| 1075 | int starting_id, |
| 1076 | int* id); |
| 1077 | |
| 1078 | // These are cover methods that invoke the method of the same name on |
| 1079 | // the DragController. Subclasses may wish to override rather than install |
| 1080 | // a DragController. |
| 1081 | // See DragController for a description of these methods. |
| 1082 | virtual int GetDragOperations(int press_x, int press_y); |
| 1083 | virtual void WriteDragData(int press_x, int press_y, OSExchangeData* data); |
| 1084 | |
| 1085 | // Invoked from DoDrag after the drag completes. This implementation does |
| 1086 | // nothing, and is intended for subclasses to do cleanup. |
| 1087 | virtual void OnDragDone(); |
| 1088 | |
| 1089 | // Returns whether we're in the middle of a drag session that was initiated |
| 1090 | // by us. |
| 1091 | bool InDrag(); |
| 1092 | |
| 1093 | // Whether this view is enabled. |
| 1094 | bool enabled_; |
| 1095 | |
| 1096 | // Whether the view can be focused. |
| 1097 | bool focusable_; |
| 1098 | |
| 1099 | private: |
| 1100 | friend class RootView; |
| 1101 | friend class FocusManager; |
| 1102 | friend class ViewStorage; |
| 1103 | |
| 1104 | // Used to track a drag. RootView passes this into |
| 1105 | // ProcessMousePressed/Dragged. |
| 1106 | struct DragInfo { |
| 1107 | // Sets possible_drag to false and start_x/y to 0. This is invoked by |
| 1108 | // RootView prior to invoke ProcessMousePressed. |
| 1109 | void Reset(); |
| 1110 | |
| 1111 | // Sets possible_drag to true and start_x/y to the specified coordinates. |
| 1112 | // This is invoked by the target view if it detects the press may generate |
| 1113 | // a drag. |
| 1114 | void PossibleDrag(int x, int y); |
| 1115 | |
| 1116 | // Whether the press may generate a drag. |
| 1117 | bool possible_drag; |
| 1118 | |
| 1119 | // Coordinates of the mouse press. |
| 1120 | int start_x; |
| 1121 | int start_y; |
| 1122 | }; |
| 1123 | |
| 1124 | // RootView invokes these. These in turn invoke the appropriate OnMouseXXX |
| 1125 | // method. If a drag is detected, DoDrag is invoked. |
| 1126 | bool ProcessMousePressed(const MouseEvent& e, DragInfo* drop_info); |
| 1127 | bool ProcessMouseDragged(const MouseEvent& e, DragInfo* drop_info); |
| 1128 | void ProcessMouseReleased(const MouseEvent& e, bool canceled); |
| 1129 | |
| 1130 | // Starts a drag and drop operation originating from this view. This invokes |
| 1131 | // WriteDragData to write the data and GetDragOperations to determine the |
| 1132 | // supported drag operations. When done, OnDragDone is invoked. |
| 1133 | void DoDrag(const ChromeViews::MouseEvent& e, int press_x, int press_y); |
| 1134 | |
| 1135 | // Adds a child View at the specified position. |floating_view| should be true |
| 1136 | // if the |v| is a floating view. |
| 1137 | void AddChildView(int index, View* v, bool floating_view); |
| 1138 | |
| 1139 | // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, |
| 1140 | // the next and previous focusable views of views pointing to this view are |
| 1141 | // updated. If |update_tool_tip| is true, the tooltip is updated. If |
| 1142 | // |delete_removed_view| is true, the view is also deleted (if it is parent |
| 1143 | // owned). |
| 1144 | void DoRemoveChildView(View* view, |
| 1145 | bool update_focus_cycle, |
| 1146 | bool update_tool_tip, |
| 1147 | bool delete_removed_view); |
| 1148 | |
| 1149 | // Sets the parent View. This is called automatically by AddChild and is |
| 1150 | // thus private. |
| 1151 | void SetParent(View *parent); |
| 1152 | |
| 1153 | // Call ViewHierarchyChanged for all child views on all parents |
| 1154 | void PropagateRemoveNotifications(View* parent); |
| 1155 | |
| 1156 | // Call ViewHierarchyChanged for all children |
| 1157 | void PropagateAddNotifications(View* parent, View* child); |
| 1158 | |
| 1159 | // Call VisibilityChanged() recursively for all children. |
| 1160 | void PropagateVisibilityNotifications(View* from, bool is_visible); |
| 1161 | |
| 1162 | // Takes care of registering/unregistering accelerators if |
| 1163 | // |register_accelerators| true and calls ViewHierarchyChanged(). |
| 1164 | void ViewHierarchyChangedImpl(bool register_accelerators, |
| 1165 | bool is_add, View *parent, View *child); |
| 1166 | |
| 1167 | // This is the actual implementation for ConvertPointToView() |
| 1168 | // Attempts a parent -> child conversion and then a |
| 1169 | // child -> parent conversion if try_other_direction is true |
| 1170 | static void ConvertPointToView(View* src, |
| 1171 | View *dst, |
| 1172 | gfx::Point* point, |
| 1173 | bool try_other_direction); |
| 1174 | |
| 1175 | // Propagates UpdateTooltip() to the TooltipManager for the ViewContainer. |
| 1176 | // This must be invoked any time the View hierarchy changes in such a way |
| 1177 | // the view under the mouse differs. For example, if the bounds of a View is |
| 1178 | // changed, this is invoked. Similarly, as Views are added/removed, this |
| 1179 | // is invoked. |
| 1180 | void UpdateTooltip(); |
| 1181 | |
| 1182 | // Recursively descends through all descendant views, |
| 1183 | // registering/unregistering all views that want visible bounds in root |
| 1184 | // view notification. |
| 1185 | static void RegisterChildrenForVisibleBoundsNotification(RootView* root, |
| 1186 | View* view); |
| 1187 | static void UnregisterChildrenForVisibleBoundsNotification(RootView* root, |
| 1188 | View* view); |
| 1189 | |
| 1190 | // Adds/removes view to the list of descendants that are notified any time |
| 1191 | // this views location and possibly size are changed. |
| 1192 | void AddDescendantToNotify(View* view); |
| 1193 | void RemoveDescendantToNotify(View* view); |
| 1194 | |
| 1195 | // Initialize the previous/next focusable views of the specified view relative |
| 1196 | // to the view at the specified index. |
| 1197 | void InitFocusSiblings(View* view, int index); |
| 1198 | |
| 1199 | // Actual implementation of PrintFocusHierarchy. |
| 1200 | void PrintViewHierarchyImp(int indent); |
| 1201 | void PrintFocusHierarchyImp(int indent); |
| 1202 | |
| 1203 | // Registers/unregister this view's keyboard accelerators with the |
| 1204 | // FocusManager. |
| 1205 | void RegisterAccelerators(); |
| 1206 | void UnregisterAccelerators(); |
| 1207 | |
| 1208 | // Returns the number of children that are actually attached floating views. |
| 1209 | int GetFloatingViewCount() const; |
| 1210 | |
| 1211 | // Returns the id for this floating view. |
| 1212 | int GetFloatingViewID(); |
| 1213 | |
| 1214 | // Returns whether this view is a floating view. |
| 1215 | bool IsFloatingView(); |
| 1216 | |
| 1217 | // Sets in |path| the path in the view hierarchy from |start| to |end| (the |
| 1218 | // path is the list of indexes in each view's children to get from |start| |
| 1219 | // to |end|). |
| 1220 | // Returns true if |start| and |view| are connected and the |path| has been |
| 1221 | // retrieved succesfully, false otherwise. |
| 1222 | static bool GetViewPath(View* start, View* end, std::vector<int>* path); |
| 1223 | |
| 1224 | // Returns the view at the end of the specified |path|, starting at the |
| 1225 | // |start| view. |
| 1226 | static View* GetViewForPath(View* start, const std::vector<int>& path); |
| 1227 | |
| 1228 | // This view's parent |
| 1229 | View *parent_; |
| 1230 | |
| 1231 | // This view's children. |
| 1232 | typedef std::vector<View*> ViewList; |
| 1233 | ViewList child_views_; |
| 1234 | |
| 1235 | // List of floating children. A floating view is always referenced by |
| 1236 | // child_views_ and will be deleted on destruction just like any other |
| 1237 | // child view. |
| 1238 | ViewList floating_views_; |
| 1239 | |
| 1240 | // Maps a floating view to its floating view id. |
| 1241 | std::map<View*, int> floating_views_ids_; |
| 1242 | |
| 1243 | // Whether we want the focus to be restored. This is used to store/restore |
| 1244 | // focus for floating views. |
| 1245 | bool should_restore_focus_; |
| 1246 | |
| 1247 | // The View's LayoutManager defines the sizing heuristics applied to child |
| 1248 | // Views. The default is absolute positioning according to bounds_. |
| 1249 | scoped_ptr<LayoutManager> layout_manager_; |
| 1250 | |
| 1251 | // Visible state |
| 1252 | bool is_visible_; |
| 1253 | |
| 1254 | // Background |
| 1255 | Background* background_; |
| 1256 | |
| 1257 | // Border. |
| 1258 | Border* border_; |
| 1259 | |
| 1260 | // Whether this view is owned by its parent. |
| 1261 | bool is_parent_owned_; |
| 1262 | |
| 1263 | // See SetNotifyWhenVisibleBoundsInRootChanges. |
| 1264 | bool notify_when_visible_bounds_in_root_changes_; |
| 1265 | |
| 1266 | // Whether or not RegisterViewForVisibleBoundsNotification on the RootView |
| 1267 | // has been invoked. |
| 1268 | bool registered_for_visible_bounds_notification_; |
| 1269 | |
| 1270 | // List of descendants wanting notification when their visible bounds change. |
| 1271 | scoped_ptr<ViewList> descendants_to_notify_; |
| 1272 | |
| 1273 | // Next view to be focused when the Tab key is pressed. |
| 1274 | View* next_focusable_view_; |
| 1275 | |
| 1276 | // Next view to be focused when the Shift-Tab key combination is pressed. |
| 1277 | View* previous_focusable_view_; |
| 1278 | |
| 1279 | // The list of accelerators. |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 1280 | scoped_ptr<std::vector<Accelerator> > accelerators_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1281 | |
| 1282 | // The task used to restore automatically the focus to the last focused |
| 1283 | // floating view. |
| 1284 | RestoreFocusTask* restore_focus_view_task_; |
| 1285 | |
| 1286 | // The menu controller. |
| 1287 | ContextMenuController* context_menu_controller_; |
| 1288 | |
| 1289 | // The accessibility implementation for this View. |
| 1290 | scoped_ptr<AccessibleWrapper> accessibility_; |
| 1291 | |
| 1292 | DragController* drag_controller_; |
| 1293 | |
| 1294 | // Indicates whether or not the view is going to be mirrored (that is, use a |
| 1295 | // right-to-left UI layout) if the locale's language is a right-to-left |
| 1296 | // language like Arabic or Hebrew. |
| 1297 | bool ui_mirroring_is_enabled_for_rtl_languages_; |
| 1298 | |
| 1299 | // Indicates whether or not the ChromeCanvas object passed to View::Paint() |
| 1300 | // is going to be flipped horizontally (using the appropriate transform) on |
| 1301 | // right-to-left locales for this View. |
| 1302 | bool flip_canvas_on_paint_for_rtl_ui_; |
| 1303 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 1304 | DISALLOW_COPY_AND_ASSIGN(View); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1305 | }; |
| 1306 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 1307 | } // namespace ChromeViews |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1308 | |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 1309 | #endif // CHROME_VIEWS_VIEW_H_ |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1310 | |