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

Side by Side Diff: chrome/browser/views/bubble_border.h

Issue 195099: Convert InfoBubble to using BubbleBorder. This also replaces the border grap... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/bubble_positioner.h ('k') | chrome/browser/views/bubble_border.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_ 5 #ifndef CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_
6 #define CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_ 6 #define CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_
7 7
8 #include "third_party/skia/include/core/SkColor.h" 8 #include "third_party/skia/include/core/SkColor.h"
9 #include "views/border.h" 9 #include "views/border.h"
10 10
11 class SkBitmap; 11 class SkBitmap;
12 12
13 // Renders a round-rect border and a custom dropshadow. This can be used to 13 // Renders a round-rect border, with optional arrow (off by default), and a
14 // produce floating "bubble" objects. 14 // custom dropshadow. This can be used to produce floating "bubble" objects.
15 class BubbleBorder : public views::Border { 15 class BubbleBorder : public views::Border {
16 public: 16 public:
17 BubbleBorder() { 17 // Possible locations for the (optional) arrow.
18 enum ArrowLocation {
19 NONE,
20 TOP_LEFT,
21 TOP_RIGHT,
22 BOTTOM_LEFT,
23 BOTTOM_RIGHT
24 };
25
26 BubbleBorder() : arrow_location_(NONE), background_color_(SK_ColorWHITE) {
18 InitClass(); 27 InitClass();
19 } 28 }
20 29
21 // Returns the radius of the corner of the border. 30 // Returns the radius of the corner of the border.
22 static int GetCornerRadius() { 31 static int GetCornerRadius() {
23 // We can't safely calculate a border radius by comparing the sizes of the 32 // We can't safely calculate a border radius by comparing the sizes of the
24 // side and corner images, because either may have been extended in various 33 // side and corner images, because either may have been extended in various
25 // directions in order to do more subtle dropshadow fading or other effects. 34 // directions in order to do more subtle dropshadow fading or other effects.
26 // So we hardcode the most accurate value. 35 // So we hardcode the most accurate value.
27 return 4; 36 return 4;
28 } 37 }
29 38
30 // Gives the desired bounds (in screen coordinates) given the rect to position 39 // Sets the location for the arrow.
31 // relative to and the size of the contained contents. The contents are 40 void set_arrow_location(ArrowLocation arrow_location) {
32 // centered underneath the supplied rect. 41 arrow_location_ = arrow_location;
42 }
43
44 // Sets the background color for the arrow body. This is irrelevant if you do
45 // not also set the arrow location to something other than NONE.
46 void set_background_color(SkColor background_color) {
47 background_color_ = background_color;
48 }
49
50 // For borders with an arrow, gives the desired bounds (in screen coordinates)
51 // given the rect to point to and the size of the contained contents. This
52 // depends on the arrow location, so if you change that, you should call this
53 // again to find out the new coordinates.
54 //
55 // For borders without an arrow, gives the bounds with the content centered
56 // underneath the supplied rect.
33 gfx::Rect GetBounds(const gfx::Rect& position_relative_to, 57 gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
34 const gfx::Size& contents_size) const; 58 const gfx::Size& contents_size) const;
35 59
36 // Overridden from views::Border: 60 // Overridden from views::Border:
37 virtual void GetInsets(gfx::Insets* insets) const; 61 virtual void GetInsets(gfx::Insets* insets) const;
38 62
39 private: 63 private:
40 // Loads images if necessary. 64 // Loads images if necessary.
41 static void InitClass(); 65 static void InitClass();
42 66
43 virtual ~BubbleBorder() { } 67 virtual ~BubbleBorder() { }
44 68
69 // Returns true if there is an arrow and it is positioned on the top edge.
70 bool arrow_is_top() const {
71 return (arrow_location_ == TOP_LEFT) || (arrow_location_ == TOP_RIGHT);
72 }
73
74 // Returns true if there is an arrow and it is positioned on the left side.
75 bool arrow_is_left() const {
76 return (arrow_location_ == TOP_LEFT) || (arrow_location_ == BOTTOM_LEFT);
77 }
78
45 // Overridden from views::Border: 79 // Overridden from views::Border:
46 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; 80 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const;
47 81
48 // Border graphics. 82 // Border graphics.
49 static SkBitmap* left_; 83 static SkBitmap* left_;
50 static SkBitmap* top_left_; 84 static SkBitmap* top_left_;
51 static SkBitmap* top_; 85 static SkBitmap* top_;
52 static SkBitmap* top_right_; 86 static SkBitmap* top_right_;
53 static SkBitmap* right_; 87 static SkBitmap* right_;
54 static SkBitmap* bottom_right_; 88 static SkBitmap* bottom_right_;
55 static SkBitmap* bottom_; 89 static SkBitmap* bottom_;
56 static SkBitmap* bottom_left_; 90 static SkBitmap* bottom_left_;
91 static SkBitmap* top_arrow_;
92 static SkBitmap* bottom_arrow_;
93
94 static int arrow_x_offset_;
95
96 ArrowLocation arrow_location_;
97 SkColor background_color_;
57 98
58 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); 99 DISALLOW_COPY_AND_ASSIGN(BubbleBorder);
59 }; 100 };
60 101
61 #endif // #ifndef CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_ 102 #endif // #ifndef CHROME_BROWSER_VIEWS_BUBBLE_BORDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/bubble_positioner.h ('k') | chrome/browser/views/bubble_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698