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

Side by Side Diff: ui/views/bubble/bubble_border.h

Issue 454173002: Fixed BubbleBorder sizing problems & added unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed construction order of the TrayBubbleView/TrayBubbleWrapper in WebNotificationBubbleWrapper co… Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
6 #define UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 6 #define UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/gfx/image/image_skia.h"
10 #include "ui/views/background.h" 12 #include "ui/views/background.h"
11 #include "ui/views/border.h" 13 #include "ui/views/border.h"
12 14
13 namespace gfx { 15 namespace gfx {
14 class ImageSkia;
15 class Rect; 16 class Rect;
16 } 17 }
17 18
18 namespace views { 19 namespace views {
20 class Painter;
19 21
20 namespace internal { 22 namespace internal {
21 struct BorderImages; 23
22 } 24 // A helper that combines each border image-set painter with arrows and metrics.
25 struct BorderImages {
26 BorderImages(const int border_image_ids[],
27 const int arrow_image_ids[],
28 int border_interior_thickness,
29 int arrow_interior_thickness,
30 int corner_radius);
31 virtual ~BorderImages();
32
33 scoped_ptr<Painter> border_painter;
34 gfx::ImageSkia left_arrow;
35 gfx::ImageSkia top_arrow;
36 gfx::ImageSkia right_arrow;
37 gfx::ImageSkia bottom_arrow;
38
39 // The thickness of border and arrow images and their interior areas.
40 // Thickness is the width of left/right and the height of top/bottom images.
41 // The interior is measured without including stroke or shadow pixels.
42 int border_thickness;
43 int border_interior_thickness;
44 int arrow_thickness;
45 int arrow_interior_thickness;
46 // The corner radius of the bubble's rounded-rect interior area.
47 int corner_radius;
48 };
49
50 } // namespace internal
23 51
24 // Renders a border, with optional arrow, and a custom dropshadow. 52 // Renders a border, with optional arrow, and a custom dropshadow.
25 // This can be used to produce floating "bubble" objects with rounded corners. 53 // This can be used to produce floating "bubble" objects with rounded corners.
26 class VIEWS_EXPORT BubbleBorder : public Border { 54 class VIEWS_EXPORT BubbleBorder : public Border {
27 public: 55 public:
28 // Possible locations for the (optional) arrow. 56 // Possible locations for the (optional) arrow.
29 // 0 bit specifies left or right. 57 // 0 bit specifies left or right.
30 // 1 bit specifies top or bottom. 58 // 1 bit specifies top or bottom.
31 // 2 bit specifies horizontal or vertical. 59 // 2 bit specifies horizontal or vertical.
32 // 3 bit specifies whether the arrow at the center of its residing edge. 60 // 3 bit specifies whether the arrow at the center of its residing edge.
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 194
167 // Gets the arrow offset to use. 195 // Gets the arrow offset to use.
168 int GetArrowOffset(const gfx::Size& border_size) const; 196 int GetArrowOffset(const gfx::Size& border_size) const;
169 197
170 // Overridden from Border: 198 // Overridden from Border:
171 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; 199 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE;
172 virtual gfx::Insets GetInsets() const OVERRIDE; 200 virtual gfx::Insets GetInsets() const OVERRIDE;
173 virtual gfx::Size GetMinimumSize() const OVERRIDE; 201 virtual gfx::Size GetMinimumSize() const OVERRIDE;
174 202
175 private: 203 private:
204 FRIEND_TEST_ALL_PREFIXES(BubbleBorderTest, GetSizeForContentsSizeTest);
205 FRIEND_TEST_ALL_PREFIXES(BubbleBorderTest, GetBoundsOriginTest);
206
207 // The border and arrow stroke size used in image assets, in pixels.
208 static const int kStroke;
209
176 gfx::Size GetSizeForContentsSize(const gfx::Size& contents_size) const; 210 gfx::Size GetSizeForContentsSize(const gfx::Size& contents_size) const;
177 gfx::ImageSkia* GetArrowImage() const; 211 gfx::ImageSkia* GetArrowImage() const;
178 gfx::Rect GetArrowRect(const gfx::Rect& bounds) const; 212 gfx::Rect GetArrowRect(const gfx::Rect& bounds) const;
179 void DrawArrow(gfx::Canvas* canvas, const gfx::Rect& arrow_bounds) const; 213 void DrawArrow(gfx::Canvas* canvas, const gfx::Rect& arrow_bounds) const;
180 214
215 internal::BorderImages* GetImagesForTest() const;
216
181 Arrow arrow_; 217 Arrow arrow_;
182 int arrow_offset_; 218 int arrow_offset_;
183 ArrowPaintType arrow_paint_type_; 219 ArrowPaintType arrow_paint_type_;
184 BubbleAlignment alignment_; 220 BubbleAlignment alignment_;
185 Shadow shadow_; 221 Shadow shadow_;
186 internal::BorderImages* images_; 222 internal::BorderImages* images_;
187 SkColor background_color_; 223 SkColor background_color_;
188 bool use_theme_background_color_; 224 bool use_theme_background_color_;
189 225
190 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); 226 DISALLOW_COPY_AND_ASSIGN(BubbleBorder);
(...skipping 10 matching lines...) Expand all
201 237
202 private: 238 private:
203 BubbleBorder* border_; 239 BubbleBorder* border_;
204 240
205 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); 241 DISALLOW_COPY_AND_ASSIGN(BubbleBackground);
206 }; 242 };
207 243
208 } // namespace views 244 } // namespace views
209 245
210 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 246 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698