| OLD | NEW |
| 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_BUBBLE_BUBBLE_BORDER_H_ | 5 #ifndef VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
| 6 #define VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 6 #define VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "views/background.h" | 9 #include "views/background.h" |
| 10 #include "views/border.h" | 10 #include "views/border.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 BOTTOM_LEFT = 2, | 27 BOTTOM_LEFT = 2, |
| 28 BOTTOM_RIGHT = 3, | 28 BOTTOM_RIGHT = 3, |
| 29 LEFT_TOP = 4, | 29 LEFT_TOP = 4, |
| 30 RIGHT_TOP = 5, | 30 RIGHT_TOP = 5, |
| 31 LEFT_BOTTOM = 6, | 31 LEFT_BOTTOM = 6, |
| 32 RIGHT_BOTTOM = 7, | 32 RIGHT_BOTTOM = 7, |
| 33 NONE = 8, // No arrow. Positioned under the supplied rect. | 33 NONE = 8, // No arrow. Positioned under the supplied rect. |
| 34 FLOAT = 9 // No arrow. Centered over the supplied rect. | 34 FLOAT = 9 // No arrow. Centered over the supplied rect. |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 enum Shadow { |
| 38 SHADOW = 0, |
| 39 NO_SHADOW = 1 |
| 40 }; |
| 41 |
| 37 // The position of the bubble in relation to the anchor. | 42 // The position of the bubble in relation to the anchor. |
| 38 enum BubbleAlignment { | 43 enum BubbleAlignment { |
| 39 // The tip of the arrow points to the middle of the anchor. | 44 // The tip of the arrow points to the middle of the anchor. |
| 40 ALIGN_ARROW_TO_MID_ANCHOR, | 45 ALIGN_ARROW_TO_MID_ANCHOR, |
| 41 // The edge nearest to the arrow is lined up with the edge of the anchor. | 46 // The edge nearest to the arrow is lined up with the edge of the anchor. |
| 42 ALIGN_EDGE_TO_ANCHOR_EDGE | 47 ALIGN_EDGE_TO_ANCHOR_EDGE |
| 43 }; | 48 }; |
| 44 | 49 |
| 45 explicit BubbleBorder(ArrowLocation arrow_location) | 50 BubbleBorder(ArrowLocation arrow_location, Shadow shadow); |
| 46 : override_arrow_offset_(0), | |
| 47 arrow_location_(arrow_location), | |
| 48 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), | |
| 49 background_color_(SK_ColorWHITE) { | |
| 50 InitClass(); | |
| 51 } | |
| 52 | 51 |
| 53 // Returns the radius of the corner of the border. | 52 // Returns the radius of the corner of the border. |
| 54 static int GetCornerRadius() { | 53 static int GetCornerRadius() { |
| 55 // We can't safely calculate a border radius by comparing the sizes of the | 54 // We can't safely calculate a border radius by comparing the sizes of the |
| 56 // side and corner images, because either may have been extended in various | 55 // side and corner images, because either may have been extended in various |
| 57 // directions in order to do more subtle dropshadow fading or other effects. | 56 // directions in order to do more subtle dropshadow fading or other effects. |
| 58 // So we hardcode the most accurate value. | 57 // So we hardcode the most accurate value. |
| 59 return 4; | 58 return 4; |
| 60 } | 59 } |
| 61 | 60 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // Sets a fixed offset for the arrow from the beginning of corresponding edge. | 109 // Sets a fixed offset for the arrow from the beginning of corresponding edge. |
| 111 // The arrow will still point to the same location but the bubble will shift | 110 // The arrow will still point to the same location but the bubble will shift |
| 112 // location to make that happen. Returns actuall arrow offset, in case of | 111 // location to make that happen. Returns actuall arrow offset, in case of |
| 113 // overflow it differ from desired. | 112 // overflow it differ from desired. |
| 114 int SetArrowOffset(int offset, const gfx::Size& contents_size); | 113 int SetArrowOffset(int offset, const gfx::Size& contents_size); |
| 115 | 114 |
| 116 // Overridden from views::Border: | 115 // Overridden from views::Border: |
| 117 virtual void GetInsets(gfx::Insets* insets) const; | 116 virtual void GetInsets(gfx::Insets* insets) const; |
| 118 | 117 |
| 119 private: | 118 private: |
| 119 struct BorderImages; |
| 120 |
| 120 // Loads images if necessary. | 121 // Loads images if necessary. |
| 121 static void InitClass(); | 122 static BorderImages* GetBorderImages(Shadow shadow); |
| 122 | 123 |
| 123 virtual ~BubbleBorder(); | 124 virtual ~BubbleBorder(); |
| 124 | 125 |
| 125 // Overridden from views::Border: | 126 // Overridden from views::Border: |
| 126 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; | 127 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; |
| 127 | 128 |
| 128 void DrawEdgeWithArrow(gfx::Canvas* canvas, | 129 void DrawEdgeWithArrow(gfx::Canvas* canvas, |
| 129 bool is_horizontal, | 130 bool is_horizontal, |
| 130 SkBitmap* edge, | 131 SkBitmap* edge, |
| 131 SkBitmap* arrow, | 132 SkBitmap* arrow, |
| 132 int start_x, | 133 int start_x, |
| 133 int start_y, | 134 int start_y, |
| 134 int before_arrow, | 135 int before_arrow, |
| 135 int after_arrow, | 136 int after_arrow, |
| 136 int offset) const; | 137 int offset) const; |
| 137 | 138 |
| 138 void DrawArrowInterior(gfx::Canvas* canvas, | 139 void DrawArrowInterior(gfx::Canvas* canvas, |
| 139 bool is_horizontal, | 140 bool is_horizontal, |
| 140 int tip_x, | 141 int tip_x, |
| 141 int tip_y, | 142 int tip_y, |
| 142 int shift_x, | 143 int shift_x, |
| 143 int shift_y) const; | 144 int shift_y) const; |
| 144 | 145 |
| 145 // Border graphics. | 146 // Border graphics. |
| 146 static SkBitmap* left_; | 147 struct BorderImages* images_; |
| 147 static SkBitmap* top_left_; | 148 |
| 148 static SkBitmap* top_; | 149 // Image bundles. |
| 149 static SkBitmap* top_right_; | 150 static struct BorderImages* normal_images_; |
| 150 static SkBitmap* right_; | 151 static struct BorderImages* shadow_images_; |
| 151 static SkBitmap* bottom_right_; | |
| 152 static SkBitmap* bottom_; | |
| 153 static SkBitmap* bottom_left_; | |
| 154 static SkBitmap* left_arrow_; | |
| 155 static SkBitmap* top_arrow_; | |
| 156 static SkBitmap* right_arrow_; | |
| 157 static SkBitmap* bottom_arrow_; | |
| 158 | 152 |
| 159 // Minimal offset of the arrow from the closet edge of bounding rect. | 153 // Minimal offset of the arrow from the closet edge of bounding rect. |
| 160 static int arrow_offset_; | 154 int arrow_offset_; |
| 161 | 155 |
| 162 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. | 156 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. |
| 163 int override_arrow_offset_; | 157 int override_arrow_offset_; |
| 164 | 158 |
| 165 ArrowLocation arrow_location_; | 159 ArrowLocation arrow_location_; |
| 166 BubbleAlignment alignment_; | 160 BubbleAlignment alignment_; |
| 167 SkColor background_color_; | 161 SkColor background_color_; |
| 168 | 162 |
| 169 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); | 163 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); |
| 170 }; | 164 }; |
| 171 | 165 |
| 172 // A Background that clips itself to the specified BubbleBorder and uses | 166 // A Background that clips itself to the specified BubbleBorder and uses |
| 173 // the background color of the BubbleBorder. | 167 // the background color of the BubbleBorder. |
| 174 class VIEWS_EXPORT BubbleBackground : public views::Background { | 168 class VIEWS_EXPORT BubbleBackground : public views::Background { |
| 175 public: | 169 public: |
| 176 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} | 170 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} |
| 177 | 171 |
| 178 // Background overrides. | 172 // Background overrides. |
| 179 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; | 173 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; |
| 180 | 174 |
| 181 private: | 175 private: |
| 182 BubbleBorder* border_; | 176 BubbleBorder* border_; |
| 183 | 177 |
| 184 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); | 178 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); |
| 185 }; | 179 }; |
| 186 | 180 |
| 187 } // namespace views | 181 } // namespace views |
| 188 | 182 |
| 189 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 183 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
| OLD | NEW |