| 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 "views/examples/bubble_example.h" | 5 #include "views/examples/bubble_example.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "views/bubble/bubble_delegate.h" | 8 #include "views/bubble/bubble_delegate.h" |
| 9 #include "views/controls/button/text_button.h" | 9 #include "views/controls/button/text_button.h" |
| 10 #include "views/controls/label.h" | 10 #include "views/controls/label.h" |
| 11 #include "views/layout/box_layout.h" | 11 #include "views/layout/box_layout.h" |
| 12 #include "views/layout/fill_layout.h" | 12 #include "views/layout/fill_layout.h" |
| 13 #include "views/widget/widget.h" | 13 #include "views/widget/widget.h" |
| 14 | 14 |
| 15 namespace examples { | 15 namespace examples { |
| 16 | 16 |
| 17 struct BubbleConfig { | 17 struct BubbleConfig { |
| 18 string16 label; | 18 string16 label; |
| 19 SkColor color; | 19 SkColor color; |
| 20 gfx::Point anchor_point; | 20 views::View* anchor_view; |
| 21 views::BubbleBorder::ArrowLocation arrow; | 21 views::BubbleBorder::ArrowLocation arrow; |
| 22 bool fade_in; | 22 bool fade_in; |
| 23 bool fade_out; | 23 bool fade_out; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 // Create four types of bubbles, one without arrow, one with an arrow, one | 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. | 27 // that fades in, and another that fades out and won't close on the escape key. |
| 28 BubbleConfig kRoundConfig = { ASCIIToUTF16("RoundBubble"), 0xFFC1B1E1, | 28 BubbleConfig kRoundConfig = { ASCIIToUTF16("Round"), 0xFFC1B1E1, NULL, |
| 29 gfx::Point(), views::BubbleBorder::NONE, false, false }; | 29 views::BubbleBorder::NONE, false, false }; |
| 30 BubbleConfig kArrowConfig = { ASCIIToUTF16("ArrowBubble"), SK_ColorGRAY, | 30 BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL, |
| 31 gfx::Point(), views::BubbleBorder::TOP_LEFT, false, false }; | 31 views::BubbleBorder::TOP_LEFT, false, false }; |
| 32 BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeInBubble"), SK_ColorYELLOW, | 32 BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL, |
| 33 gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, true, false }; | 33 views::BubbleBorder::BOTTOM_RIGHT, true, false }; |
| 34 BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOutBubble"), SK_ColorWHITE, | 34 BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL, |
| 35 gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, false, true }; | 35 views::BubbleBorder::LEFT_TOP, false, true }; |
| 36 | 36 |
| 37 class ExampleBubbleDelegateView : public views::BubbleDelegateView { | 37 class ExampleBubbleDelegateView : public views::BubbleDelegateView { |
| 38 public: | 38 public: |
| 39 ExampleBubbleDelegateView(const BubbleConfig& config) | 39 ExampleBubbleDelegateView(const BubbleConfig& config) |
| 40 : BubbleDelegateView(config.anchor_point, config.arrow, config.color), | 40 : BubbleDelegateView(config.anchor_view, config.arrow, config.color), |
| 41 label_(config.label) {} | 41 label_(config.label) {} |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 virtual void Init() OVERRIDE { | 44 virtual void Init() OVERRIDE { |
| 45 SetLayoutManager(new views::FillLayout()); | 45 SetLayoutManager(new views::FillLayout()); |
| 46 views::Label* label = new views::Label(label_); | 46 views::Label* label = new views::Label(label_); |
| 47 AddChildView(label); | 47 AddChildView(label); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 BubbleConfig config; | 74 BubbleConfig config; |
| 75 if (sender == round_) | 75 if (sender == round_) |
| 76 config = kRoundConfig; | 76 config = kRoundConfig; |
| 77 else if (sender == arrow_) | 77 else if (sender == arrow_) |
| 78 config = kArrowConfig; | 78 config = kArrowConfig; |
| 79 else if (sender == fade_in_) | 79 else if (sender == fade_in_) |
| 80 config = kFadeInConfig; | 80 config = kFadeInConfig; |
| 81 else if (sender == fade_out_) | 81 else if (sender == fade_out_) |
| 82 config = kFadeOutConfig; | 82 config = kFadeOutConfig; |
| 83 | 83 |
| 84 config.anchor_point.set_x(sender->width() / 2); | 84 config.anchor_view = sender; |
| 85 config.anchor_point.set_y(sender->height() / 2); | |
| 86 views::View::ConvertPointToScreen(sender, &config.anchor_point); | |
| 87 | |
| 88 ExampleBubbleDelegateView* bubble_delegate = | 85 ExampleBubbleDelegateView* bubble_delegate = |
| 89 new ExampleBubbleDelegateView(config); | 86 new ExampleBubbleDelegateView(config); |
| 90 views::BubbleDelegateView::CreateBubble(bubble_delegate, | 87 views::BubbleDelegateView::CreateBubble(bubble_delegate); |
| 91 example_view()->GetWidget()); | |
| 92 | 88 |
| 93 if (config.fade_in) | 89 if (config.fade_in) |
| 94 bubble_delegate->StartFade(true); | 90 bubble_delegate->StartFade(true); |
| 95 else | 91 else |
| 96 bubble_delegate->Show(); | 92 bubble_delegate->Show(); |
| 97 | 93 |
| 98 if (config.fade_out) { | 94 if (config.fade_out) { |
| 99 bubble_delegate->set_close_on_esc(false); | 95 bubble_delegate->set_close_on_esc(false); |
| 100 bubble_delegate->StartFade(false); | 96 bubble_delegate->StartFade(false); |
| 101 } | 97 } |
| 102 } | 98 } |
| 103 | 99 |
| 104 } // namespace examples | 100 } // namespace examples |
| OLD | NEW |