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

Side by Side Diff: ui/views/examples/bubble_example.cc

Issue 8687013: Get the examples to run in aura_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | « ui/views/examples/bubble_example.h ('k') | ui/views/examples/button_example.h » ('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) 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 "ui/views/examples/bubble_example.h" 5 #include "ui/views/examples/bubble_example.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "ui/views/bubble/bubble_delegate.h" 8 #include "ui/views/bubble/bubble_delegate.h"
9 #include "ui/views/controls/button/text_button.h" 9 #include "ui/views/controls/button/text_button.h"
10 #include "ui/views/layout/box_layout.h" 10 #include "ui/views/layout/box_layout.h"
11 #include "ui/views/layout/fill_layout.h" 11 #include "ui/views/layout/fill_layout.h"
12 #include "ui/views/widget/widget.h" 12 #include "ui/views/widget/widget.h"
13 #include "views/controls/label.h" 13 #include "views/controls/label.h"
14 14
15 namespace views {
15 namespace examples { 16 namespace examples {
16 17
17 struct BubbleConfig { 18 struct BubbleConfig {
18 string16 label; 19 string16 label;
19 SkColor color; 20 SkColor color;
20 views::View* anchor_view; 21 View* anchor_view;
21 views::BubbleBorder::ArrowLocation arrow; 22 BubbleBorder::ArrowLocation arrow;
22 bool fade_in; 23 bool fade_in;
23 bool fade_out; 24 bool fade_out;
24 }; 25 };
25 26
26 // Create four types of bubbles, one without arrow, one with an arrow, one 27 // Create four types of bubbles, one without arrow, one with an arrow, one
27 // that fades in, and another that fades out and won't close on the escape key. 28 // that fades in, and another that fades out and won't close on the escape key.
28 BubbleConfig kRoundConfig = { ASCIIToUTF16("Round"), 0xFFC1B1E1, NULL, 29 BubbleConfig kRoundConfig = { ASCIIToUTF16("Round"), 0xFFC1B1E1, NULL,
29 views::BubbleBorder::NONE, false, false }; 30 BubbleBorder::NONE, false, false };
30 BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL, 31 BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL,
31 views::BubbleBorder::TOP_LEFT, false, false }; 32 BubbleBorder::TOP_LEFT, false, false };
32 BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL, 33 BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL,
33 views::BubbleBorder::BOTTOM_RIGHT, true, false }; 34 BubbleBorder::BOTTOM_RIGHT, true, false };
34 BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL, 35 BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL,
35 views::BubbleBorder::LEFT_TOP, false, true }; 36 BubbleBorder::LEFT_TOP, false, true };
36 37
37 class ExampleBubbleDelegateView : public views::BubbleDelegateView { 38 class ExampleBubbleDelegateView : public BubbleDelegateView {
38 public: 39 public:
39 ExampleBubbleDelegateView(const BubbleConfig& config) 40 ExampleBubbleDelegateView(const BubbleConfig& config)
40 : BubbleDelegateView(config.anchor_view, config.arrow, config.color), 41 : BubbleDelegateView(config.anchor_view, config.arrow, config.color),
41 label_(config.label) {} 42 label_(config.label) {}
42 43
43 protected: 44 protected:
44 virtual void Init() OVERRIDE { 45 virtual void Init() OVERRIDE {
45 SetLayoutManager(new views::FillLayout()); 46 SetLayoutManager(new FillLayout());
46 views::Label* label = new views::Label(label_); 47 Label* label = new Label(label_);
47 AddChildView(label); 48 AddChildView(label);
48 } 49 }
49 50
50 private: 51 private:
51 string16 label_; 52 string16 label_;
52 }; 53 };
53 54
54 BubbleExample::BubbleExample(ExamplesMain* main) 55 BubbleExample::BubbleExample() : ExampleBase("Bubble") {}
55 : ExampleBase(main, "Bubble") {}
56 56
57 BubbleExample::~BubbleExample() {} 57 BubbleExample::~BubbleExample() {}
58 58
59 void BubbleExample::CreateExampleView(views::View* container) { 59 void BubbleExample::CreateExampleView(View* container) {
60 container->SetLayoutManager( 60 container->SetLayoutManager(
61 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1)); 61 new BoxLayout(BoxLayout::kHorizontal, 0, 0, 1));
62 round_ = new views::TextButton(this, kRoundConfig.label); 62 round_ = new TextButton(this, kRoundConfig.label);
63 arrow_ = new views::TextButton(this, kArrowConfig.label); 63 arrow_ = new TextButton(this, kArrowConfig.label);
64 fade_in_ = new views::TextButton(this, kFadeInConfig.label); 64 fade_in_ = new TextButton(this, kFadeInConfig.label);
65 fade_out_ = new views::TextButton(this, kFadeOutConfig.label); 65 fade_out_ = new TextButton(this, kFadeOutConfig.label);
66 container->AddChildView(round_); 66 container->AddChildView(round_);
67 container->AddChildView(arrow_); 67 container->AddChildView(arrow_);
68 container->AddChildView(fade_in_); 68 container->AddChildView(fade_in_);
69 container->AddChildView(fade_out_); 69 container->AddChildView(fade_out_);
70 } 70 }
71 71
72 void BubbleExample::ButtonPressed(views::Button* sender, 72 void BubbleExample::ButtonPressed(Button* sender, const Event& event) {
73 const views::Event& event) {
74 BubbleConfig config; 73 BubbleConfig config;
75 if (sender == round_) 74 if (sender == round_)
76 config = kRoundConfig; 75 config = kRoundConfig;
77 else if (sender == arrow_) 76 else if (sender == arrow_)
78 config = kArrowConfig; 77 config = kArrowConfig;
79 else if (sender == fade_in_) 78 else if (sender == fade_in_)
80 config = kFadeInConfig; 79 config = kFadeInConfig;
81 else if (sender == fade_out_) 80 else if (sender == fade_out_)
82 config = kFadeOutConfig; 81 config = kFadeOutConfig;
83 82
84 config.anchor_view = sender; 83 config.anchor_view = sender;
85 ExampleBubbleDelegateView* bubble_delegate = 84 ExampleBubbleDelegateView* bubble_delegate =
86 new ExampleBubbleDelegateView(config); 85 new ExampleBubbleDelegateView(config);
87 views::BubbleDelegateView::CreateBubble(bubble_delegate); 86 BubbleDelegateView::CreateBubble(bubble_delegate);
88 87
89 if (config.fade_in) 88 if (config.fade_in)
90 bubble_delegate->StartFade(true); 89 bubble_delegate->StartFade(true);
91 else 90 else
92 bubble_delegate->Show(); 91 bubble_delegate->Show();
93 92
94 if (config.fade_out) { 93 if (config.fade_out) {
95 bubble_delegate->set_close_on_esc(false); 94 bubble_delegate->set_close_on_esc(false);
96 bubble_delegate->StartFade(false); 95 bubble_delegate->StartFade(false);
97 } 96 }
98 } 97 }
99 98
100 } // namespace examples 99 } // namespace examples
100 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/bubble_example.h ('k') | ui/views/examples/button_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698