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

Side by Side Diff: ui/aura_shell/examples/bubble.cc

Issue 8227003: Views Bubble API adjustments and cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 9 years, 2 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 | « no previous file | ui/aura_shell/examples/example_factory.h » ('j') | views/bubble/bubble_delegate.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
14
13 namespace examples { 15 namespace examples {
14 16
15 struct BubbleConfig { 17 struct BubbleConfig {
16 string16 label; 18 string16 label;
17 SkColor color; 19 SkColor color;
18 gfx::Rect bound; 20 gfx::Point arrow_point;
19 views::BubbleBorder::ArrowLocation arrow; 21 views::BubbleBorder::ArrowLocation arrow;
20 bool fade_out; 22 bool fade_out;
21 }; 23 };
22 24
23 class ExampleBubbleDelegateView : public views::BubbleDelegateView { 25 class ExampleBubbleDelegateView : public views::BubbleDelegateView {
24 public: 26 public:
25 ExampleBubbleDelegateView(const BubbleConfig& config, views::Widget* widget) 27 ExampleBubbleDelegateView(const BubbleConfig& config)
26 : BubbleDelegateView(widget), 28 : config_(config) {}
27 config_(config) {}
28 virtual ~ExampleBubbleDelegateView() {}
29 29
30 // Overridden from views::BubbleDelegateView 30 virtual gfx::Point GetArrowPoint() const OVERRIDE {
31 virtual views::View* GetContentsView() OVERRIDE { return this; } 31 return config_.arrow_point;
32 virtual SkColor GetFrameBackgroundColor() OVERRIDE { return config_.color; } 32 }
33 virtual gfx::Rect GetBounds() OVERRIDE { return config_.bound; } 33
34 virtual views::BubbleBorder::ArrowLocation GetFrameArrowLocation() OVERRIDE { 34 views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE {
35 return config_.arrow; 35 return config_.arrow;
36 } 36 }
37 37
38 SkColor GetColor() const OVERRIDE {
39 return config_.color;
40 }
41
42 virtual void Init() OVERRIDE {
43 SetLayoutManager(new views::FillLayout());
44 views::Label* label = new views::Label(config_.label);
45 label->set_border(views::Border::CreateSolidBorder(10, config_.color));
46 AddChildView(label);
47 }
48
38 private: 49 private:
39 const BubbleConfig config_; 50 const BubbleConfig& config_;
40
41 DISALLOW_COPY_AND_ASSIGN(ExampleBubbleDelegateView);
42 }; 51 };
43 52
44 void CreateBubble(const BubbleConfig& config, 53 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; 54 BubbleConfig config;
60 config.label = ASCIIToUTF16("PointyBubble"); 55 config.label = ASCIIToUTF16("PointyBubble");
61 config.color = SK_ColorWHITE; 56 config.color = SK_ColorWHITE;
62 config.bound = gfx::Rect(origin.x(), origin.y(), 180, 180); 57 config.arrow_point = origin;
63 config.arrow = views::BubbleBorder::TOP_LEFT; 58 config.arrow = views::BubbleBorder::TOP_LEFT;
64 config.fade_out = false; 59 config.fade_out = false;
65 CreateBubble(config, parent); 60 views::Widget* bubble = views::BubbleDelegateView::ConstructBubble(
61 new ExampleBubbleDelegateView(config), parent);
62 bubble->Show();
66 } 63 }
67 64
68 } // namespace examples 65 } // namespace examples
69 } // namespace aura_shell 66 } // namespace aura_shell
OLDNEW
« no previous file with comments | « no previous file | ui/aura_shell/examples/example_factory.h » ('j') | views/bubble/bubble_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698