Chromium Code Reviews| Index: ui/views/bubble/bubble_border.h |
| diff --git a/ui/views/bubble/bubble_border.h b/ui/views/bubble/bubble_border.h |
| index 17d1de7300fb126438d92b4210b69932e548c944..cd699d19ab8102dfd30b21ae03d83f460f3ce1ac 100644 |
| --- a/ui/views/bubble/bubble_border.h |
| +++ b/ui/views/bubble/bubble_border.h |
| @@ -24,22 +24,32 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| // 0 bit specifies left or right. |
| // 1 bit specifies top or bottom. |
| // 2 bit specifies horizontal or vertical. |
| + // 3 bit specifies whether the arrow at the center of its residing edge. |
| enum ArrowLocation { |
| - TOP_LEFT = 0, |
| - TOP_RIGHT = 1, |
| - BOTTOM_LEFT = 2, |
| - BOTTOM_RIGHT = 3, |
| - LEFT_TOP = 4, |
| - RIGHT_TOP = 5, |
| - LEFT_BOTTOM = 6, |
| - RIGHT_BOTTOM = 7, |
| - NONE = 8, // No arrow. Positioned under the supplied rect. |
| - FLOAT = 9 // No arrow. Centered over the supplied rect. |
| + TOP_LEFT = 0, |
| + TOP_RIGHT = 1, |
| + BOTTOM_LEFT = 2, |
| + BOTTOM_RIGHT = 3, |
| + LEFT_TOP = 4, |
| + RIGHT_TOP = 5, |
| + LEFT_BOTTOM = 6, |
| + RIGHT_BOTTOM = 7, |
| + TOP_CENTER = 9, |
|
msw
2012/09/20 00:07:23
Would it make more sense to specify these with bit
|
| + BOTTOM_CENTER = 11, |
| + LEFT_CENTER = 14, |
| + RIGHT_CENTER = 15, |
| + NONE = 16, // No arrow. Positioned under the supplied rect. |
| + FLOAT = 17, // No arrow. Centered over the supplied rect. |
| }; |
| enum Shadow { |
| SHADOW = 0, |
| - NO_SHADOW = 1 |
| + NO_SHADOW, |
| +#if defined(USE_AURA) |
| + BIG_SHADOW, |
| + SMALL_SHADOW, |
| +#endif |
| + SHADOW_COUNT, |
| }; |
| // The position of the bubble in relation to the anchor. |
| @@ -53,6 +63,7 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| BubbleBorder(ArrowLocation arrow_location, Shadow shadow); |
| // Returns the radius of the corner of the border. |
| + // TODO(xiyuan): Get rid of this since it's part of BorderImages now? |
| static int GetCornerRadius() { |
| // We can't safely calculate a border radius by comparing the sizes of the |
| // side and corner images, because either may have been extended in various |
| @@ -70,11 +81,13 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| BubbleAlignment alignment() const { return alignment_; } |
| static ArrowLocation horizontal_mirror(ArrowLocation loc) { |
| - return loc >= NONE ? loc : static_cast<ArrowLocation>(loc ^ 1); |
| + return (loc == TOP_CENTER || loc == BOTTOM_CENTER || loc >= NONE) ? |
| + loc : static_cast<ArrowLocation>(loc ^ 1); |
| } |
| static ArrowLocation vertical_mirror(ArrowLocation loc) { |
| - return loc >= NONE ? loc : static_cast<ArrowLocation>(loc ^ 2); |
| + return (loc == LEFT_CENTER || loc == RIGHT_CENTER || loc >= NONE) ? |
| + loc : static_cast<ArrowLocation>(loc ^ 2); |
| } |
| static bool has_arrow(ArrowLocation loc) { |
| @@ -93,6 +106,10 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| return loc >= NONE ? false : !(loc & 4); |
| } |
| + static bool is_arrow_at_center(ArrowLocation loc) { |
| + return has_arrow(loc) && !!(loc & 8); |
| + } |
| + |
| // Sets the background color for the arrow body. This is irrelevant if you do |
| // not also set the arrow location to something other than NONE. |
| void set_background_color(SkColor color) { background_color_ = color; } |
| @@ -101,6 +118,11 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; } |
| const gfx::Rect& client_bounds() const { return client_bounds_; } |
| + // Sets a fixed offset for the arrow from the beginning of corresponding edge. |
| + // The arrow will still point to the same location but the bubble will shift |
| + // location to make that happen. |
| + void set_arrow_offset(int offset) { override_arrow_offset_ = offset; } |
| + |
| // For borders with an arrow, gives the desired bounds (in screen coordinates) |
| // given the rect to point to and the size of the contained contents. This |
| // depends on the arrow location, so if you change that, you should call this |
| @@ -108,11 +130,11 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
| const gfx::Size& contents_size) const; |
| - // Sets a fixed offset for the arrow from the beginning of corresponding edge. |
| - // The arrow will still point to the same location but the bubble will shift |
| - // location to make that happen. Returns actuall arrow offset, in case of |
| - // overflow it differ from desired. |
| - int SetArrowOffset(int offset, const gfx::Size& contents_size); |
| + // Returns the corner radius of the current image set. |
| + int GetBorderCornerRadius() const; |
| + |
| + // Gets the arrow offset to use. |
| + int GetArrowOffset(const gfx::Size& border_size) const; |
| // Overridden from Border: |
| virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; |
| @@ -141,8 +163,8 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| void DrawEdgeWithArrow(gfx::Canvas* canvas, |
| bool is_horizontal, |
| - gfx::ImageSkia* edge, |
| - gfx::ImageSkia* arrow, |
| + const gfx::ImageSkia& edge, |
| + const gfx::ImageSkia& arrow, |
| int start_x, |
| int start_y, |
| int before_arrow, |
| @@ -155,8 +177,7 @@ class VIEWS_EXPORT BubbleBorder : public Border { |
| struct BorderImages* images_; |
| // Image bundles. |
| - static struct BorderImages* normal_images_; |
| - static struct BorderImages* shadow_images_; |
| + static struct BorderImages* border_images_[SHADOW_COUNT]; |
| // Minimal offset of the arrow from the closet edge of bounding rect. |
| int arrow_offset_; |