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 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "views/bubble/bubble_border.h" | 6 #include "views/bubble/bubble_border.h" |
7 #include "views/bubble/bubble_delegate.h" | 7 #include "views/bubble/bubble_delegate.h" |
8 #include "views/bubble/bubble_view.h" | 8 #include "views/bubble/bubble_view.h" |
9 #include "views/controls/label.h" | 9 #include "views/controls/label.h" |
| 10 #include "views/layout/fill_layout.h" |
10 #include "views/widget/widget.h" | 11 #include "views/widget/widget.h" |
11 | 12 |
12 namespace aura_shell { | 13 namespace aura_shell { |
13 namespace examples { | 14 namespace examples { |
14 | 15 |
15 struct BubbleConfig { | 16 struct BubbleConfig { |
16 string16 label; | 17 string16 label; |
17 SkColor color; | 18 SkColor color; |
18 gfx::Rect bound; | 19 gfx::Point anchor_point; |
19 views::BubbleBorder::ArrowLocation arrow; | 20 views::BubbleBorder::ArrowLocation arrow; |
20 bool fade_out; | |
21 }; | 21 }; |
22 | 22 |
23 class ExampleBubbleDelegateView : public views::BubbleDelegateView { | 23 class ExampleBubbleDelegateView : public views::BubbleDelegateView { |
24 public: | 24 public: |
25 ExampleBubbleDelegateView(const BubbleConfig& config, views::Widget* widget) | 25 ExampleBubbleDelegateView(const BubbleConfig& config) |
26 : BubbleDelegateView(widget), | 26 : config_(config) {} |
27 config_(config) {} | |
28 virtual ~ExampleBubbleDelegateView() {} | |
29 | 27 |
30 // Overridden from views::BubbleDelegateView | 28 virtual gfx::Point GetAnchorPoint() const OVERRIDE { |
31 virtual views::View* GetContentsView() OVERRIDE { return this; } | 29 return config_.anchor_point; |
32 virtual SkColor GetFrameBackgroundColor() OVERRIDE { return config_.color; } | 30 } |
33 virtual gfx::Rect GetBounds() OVERRIDE { return config_.bound; } | 31 |
34 virtual views::BubbleBorder::ArrowLocation GetFrameArrowLocation() OVERRIDE { | 32 views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE { |
35 return config_.arrow; | 33 return config_.arrow; |
36 } | 34 } |
37 | 35 |
| 36 SkColor GetColor() const OVERRIDE { |
| 37 return config_.color; |
| 38 } |
| 39 |
| 40 virtual void Init() OVERRIDE { |
| 41 SetLayoutManager(new views::FillLayout()); |
| 42 views::Label* label = new views::Label(config_.label); |
| 43 label->set_border(views::Border::CreateSolidBorder(10, config_.color)); |
| 44 AddChildView(label); |
| 45 } |
| 46 |
38 private: | 47 private: |
39 const BubbleConfig config_; | 48 const BubbleConfig config_; |
40 | |
41 DISALLOW_COPY_AND_ASSIGN(ExampleBubbleDelegateView); | |
42 }; | 49 }; |
43 | 50 |
44 void CreateBubble(const BubbleConfig& config, | 51 void CreatePointyBubble(views::Widget* parent, const gfx::Point& origin) { |
45 gfx::NativeWindow parent) { | |
46 views::Widget* bubble_widget = new views::Widget; | |
47 views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE); | |
48 params.delegate = new ExampleBubbleDelegateView(config, bubble_widget); | |
49 params.transparent = true; | |
50 params.bounds = config.bound; | |
51 params.parent = parent; | |
52 bubble_widget->Init(params); | |
53 bubble_widget->client_view()->AsBubbleView()->AddChildView( | |
54 new views::Label(ASCIIToUTF16("I am a ") + config.label)); | |
55 bubble_widget->Show(); | |
56 } | |
57 | |
58 void CreatePointyBubble(gfx::NativeWindow parent, const gfx::Point& origin) { | |
59 BubbleConfig config; | 52 BubbleConfig config; |
60 config.label = ASCIIToUTF16("PointyBubble"); | 53 config.label = ASCIIToUTF16("PointyBubble"); |
61 config.color = SK_ColorWHITE; | 54 config.color = SK_ColorWHITE; |
62 config.bound = gfx::Rect(origin.x(), origin.y(), 180, 180); | 55 config.anchor_point = origin; |
63 config.arrow = views::BubbleBorder::TOP_LEFT; | 56 config.arrow = views::BubbleBorder::TOP_LEFT; |
64 config.fade_out = false; | 57 views::Widget* bubble = views::BubbleDelegateView::CreateBubble( |
65 CreateBubble(config, parent); | 58 new ExampleBubbleDelegateView(config), parent); |
| 59 bubble->Show(); |
66 } | 60 } |
67 | 61 |
68 } // namespace examples | 62 } // namespace examples |
69 } // namespace aura_shell | 63 } // namespace aura_shell |
OLD | NEW |