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

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

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

Powered by Google App Engine
This is Rietveld 408576698