OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // The View also uses a simple Box Layout Manager similar to XUL's | 122 // The View also uses a simple Box Layout Manager similar to XUL's |
123 // SprocketLayout system. Alternative Layout Managers implementing the | 123 // SprocketLayout system. Alternative Layout Managers implementing the |
124 // LayoutManager interface can be used to lay out children if required. | 124 // LayoutManager interface can be used to lay out children if required. |
125 // | 125 // |
126 // It is up to the subclass to implement Painting and storage of subclass - | 126 // It is up to the subclass to implement Painting and storage of subclass - |
127 // specific properties and functionality. | 127 // specific properties and functionality. |
128 // | 128 // |
129 ///////////////////////////////////////////////////////////////////////////// | 129 ///////////////////////////////////////////////////////////////////////////// |
130 class View : public AcceleratorTarget { | 130 class View : public AcceleratorTarget { |
131 public: | 131 public: |
132 // Used in the versions of GetBounds() and x() that take a transformation | |
133 // parameter in order to determine whether or not to take into account the | |
134 // mirroring setting of the View when returning bounds positions. | |
135 enum PositionMirroringSettings { | |
136 IGNORE_MIRRORING_TRANSFORMATION = 0, | |
137 APPLY_MIRRORING_TRANSFORMATION | |
138 }; | |
139 | |
140 #if defined(TOUCH_UI) | 132 #if defined(TOUCH_UI) |
141 enum TouchStatus { | 133 enum TouchStatus { |
142 TOUCH_STATUS_UNKNOWN = 0, // Unknown touch status. This is used to indicate | 134 TOUCH_STATUS_UNKNOWN = 0, // Unknown touch status. This is used to indicate |
143 // that the touch event was not handled. | 135 // that the touch event was not handled. |
144 TOUCH_STATUS_START, // The touch event initiated a touch sequence. | 136 TOUCH_STATUS_START, // The touch event initiated a touch sequence. |
145 TOUCH_STATUS_CONTINUE, // The touch event is part of a previously | 137 TOUCH_STATUS_CONTINUE, // The touch event is part of a previously |
146 // started touch sequence. | 138 // started touch sequence. |
147 TOUCH_STATUS_END, // The touch event ended the touch sequence. | 139 TOUCH_STATUS_END, // The touch event ended the touch sequence. |
148 TOUCH_STATUS_CANCEL // The touch event was cancelled, but didn't | 140 TOUCH_STATUS_CANCEL // The touch event was cancelled, but didn't |
149 // terminate the touch sequence. | 141 // terminate the touch sequence. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Set whether this view is enabled. A disabled view does not receive keyboard | 329 // Set whether this view is enabled. A disabled view does not receive keyboard |
338 // or mouse inputs. If flag differs from the current value, SchedulePaint is | 330 // or mouse inputs. If flag differs from the current value, SchedulePaint is |
339 // invoked. | 331 // invoked. |
340 virtual void SetEnabled(bool flag); | 332 virtual void SetEnabled(bool flag); |
341 | 333 |
342 // Returns whether the view is enabled. | 334 // Returns whether the view is enabled. |
343 virtual bool IsEnabled() const; | 335 virtual bool IsEnabled() const; |
344 | 336 |
345 // RTL positioning ----------------------------------------------------------- | 337 // RTL positioning ----------------------------------------------------------- |
346 | 338 |
347 // Return the bounds of the View, relative to the parent. If | 339 // Methods for accessing the bounds and position of the view, relative to its |
348 // |settings| is IGNORE_MIRRORING_TRANSFORMATION, the function returns the | 340 // parent. The position returned is mirrored if the parent view is using a RTL |
349 // bounds_ rectangle. If |settings| is APPLY_MIRRORING_TRANSFORMATION AND the | 341 // layout. |
350 // parent View is using a right-to-left UI layout, then the function returns | |
351 // a shifted version of the bounds_ rectangle that represents the mirrored | |
352 // View bounds. | |
353 // | 342 // |
354 // NOTE: in the vast majority of the cases, the mirroring implementation is | 343 // NOTE: in the vast majority of the cases, the mirroring implementation is |
355 // transparent to the View subclasses and therefore you should use the | 344 // transparent to the View subclasses and therefore you should use the |
356 // version of GetBounds() which does not take a transformation settings | 345 // bounds() accessor instead. |
357 // parameter. | 346 gfx::Rect GetMirroredBounds() const; |
358 gfx::Rect GetBounds(PositionMirroringSettings settings) const; | 347 gfx::Point GetMirroredPosition() const; |
359 | 348 int GetMirroredX() const; |
360 // Return the left coordinate of the View, relative to the parent. If | |
361 // |settings| is IGNORE_MIRRORING_SETTINGS, the function returns the value of | |
362 // bounds_.x(). If |settings| is APPLY_MIRRORING_SETTINGS AND the parent | |
363 // View is using a right-to-left UI layout, then the function returns the | |
364 // mirrored value of bounds_.x(). | |
365 // | |
366 // NOTE: in the vast majority of the cases, the mirroring implementation is | |
367 // transparent to the View subclasses and therefore you should use the | |
368 // paremeterless version of x() when you need to get the X | |
369 // coordinate of a child View. | |
370 int GetX(PositionMirroringSettings settings) const; | |
371 | |
372 // Get the position of the View, relative to the parent. | |
373 // | |
374 // Note that if the parent uses right-to-left UI layout, then the mirrored | |
375 // position of this View is returned. Use x()/y() if you want to ignore | |
376 // mirroring. | |
377 gfx::Point GetPosition() const; | |
378 | |
379 // Returns the mirrored X position for the view, relative to the parent. If | |
380 // the parent view is not mirrored, this function returns bound_.left. | |
381 // | |
382 // UI mirroring is transparent to most View subclasses and therefore there is | |
383 // no need to call this routine from anywhere within your subclass | |
384 // implementation. | |
385 int MirroredX() const; | |
386 | 349 |
387 // Given a rectangle specified in this View's coordinate system, the function | 350 // Given a rectangle specified in this View's coordinate system, the function |
388 // computes the 'left' value for the mirrored rectangle within this View. If | 351 // computes the 'left' value for the mirrored rectangle within this View. If |
389 // the View's UI layout is not right-to-left, then bounds.x() is returned. | 352 // the View's UI layout is not right-to-left, then bounds.x() is returned. |
390 // | 353 // |
391 // UI mirroring is transparent to most View subclasses and therefore there is | 354 // UI mirroring is transparent to most View subclasses and therefore there is |
392 // no need to call this routine from anywhere within your subclass | 355 // no need to call this routine from anywhere within your subclass |
393 // implementation. | 356 // implementation. |
394 int MirroredLeftPointForRect(const gfx::Rect& rect) const; | 357 int GetMirroredXForRect(const gfx::Rect& rect) const; |
395 | 358 |
396 // Given the X coordinate of a point inside the View, this function returns | 359 // Given the X coordinate of a point inside the View, this function returns |
397 // the mirrored X coordinate of the point if the View's UI layout is | 360 // the mirrored X coordinate of the point if the View's UI layout is |
398 // right-to-left. If the layout is left-to-right, the same X coordinate is | 361 // right-to-left. If the layout is left-to-right, the same X coordinate is |
399 // returned. | 362 // returned. |
400 // | 363 // |
401 // Following are a few examples of the values returned by this function for | 364 // Following are a few examples of the values returned by this function for |
402 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: | 365 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: |
403 // | 366 // |
404 // MirroredXCoordinateInsideView(0) -> 100 | 367 // GetMirroredXCoordinateInView(0) -> 100 |
405 // MirroredXCoordinateInsideView(20) -> 80 | 368 // GetMirroredXCoordinateInView(20) -> 80 |
406 // MirroredXCoordinateInsideView(99) -> 1 | 369 // GetMirroredXCoordinateInView(99) -> 1 |
407 int MirroredXCoordinateInsideView(int x) const { | 370 int GetMirroredXInView(int x) const; |
408 return base::i18n::IsRTL() ? width() - x : x; | |
409 } | |
410 | 371 |
411 // Given a X coordinate and a width inside the View, this function returns | 372 // Given a X coordinate and a width inside the View, this function returns |
412 // the mirrored X coordinate if the View's UI layout is right-to-left. If the | 373 // the mirrored X coordinate if the View's UI layout is right-to-left. If the |
413 // layout is left-to-right, the same X coordinate is returned. | 374 // layout is left-to-right, the same X coordinate is returned. |
414 // | 375 // |
415 // Following are a few examples of the values returned by this function for | 376 // Following are a few examples of the values returned by this function for |
416 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: | 377 // a View with the bounds {0, 0, 100, 100} and a right-to-left layout: |
417 // | 378 // |
418 // MirroredXCoordinateInsideView(0, 10) -> 90 | 379 // GetMirroredXCoordinateInView(0, 10) -> 90 |
419 // MirroredXCoordinateInsideView(20, 20) -> 60 | 380 // GetMirroredXCoordinateInView(20, 20) -> 60 |
420 int MirroredXWithWidthInsideView(int x, int w) const { | 381 int GetMirroredXWithWidthInView(int x, int w) const; |
421 return base::i18n::IsRTL() ? width() - x - w : x; | |
422 } | |
423 | 382 |
424 // Layout -------------------------------------------------------------------- | 383 // Layout -------------------------------------------------------------------- |
425 | 384 |
426 // Lay out the child Views (set their bounds based on sizing heuristics | 385 // Lay out the child Views (set their bounds based on sizing heuristics |
427 // specific to the current Layout Manager) | 386 // specific to the current Layout Manager) |
428 virtual void Layout(); | 387 virtual void Layout(); |
429 | 388 |
430 // TODO(beng): I think we should remove this. | 389 // TODO(beng): I think we should remove this. |
431 // Mark this view and all parents to require a relayout. This ensures the | 390 // Mark this view and all parents to require a relayout. This ensures the |
432 // next call to Layout() will propagate to this view, even if the bounds of | 391 // next call to Layout() will propagate to this view, even if the bounds of |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 // The accessibility implementation for this View. | 1391 // The accessibility implementation for this View. |
1433 scoped_refptr<ViewAccessibility> view_accessibility_; | 1392 scoped_refptr<ViewAccessibility> view_accessibility_; |
1434 #endif | 1393 #endif |
1435 | 1394 |
1436 DISALLOW_COPY_AND_ASSIGN(View); | 1395 DISALLOW_COPY_AND_ASSIGN(View); |
1437 }; | 1396 }; |
1438 | 1397 |
1439 } // namespace views | 1398 } // namespace views |
1440 | 1399 |
1441 #endif // VIEWS_VIEW_H_ | 1400 #endif // VIEWS_VIEW_H_ |
OLD | NEW |