Index: views/examples/bubble_example.cc |
diff --git a/views/examples/bubble_example.cc b/views/examples/bubble_example.cc |
index ea3173591716de13fd5d40731b492768b5780788..4a98ff7cd18c4ec38e3f42db01de78c792781b9c 100644 |
--- a/views/examples/bubble_example.cc |
+++ b/views/examples/bubble_example.cc |
@@ -5,15 +5,12 @@ |
#include "views/examples/bubble_example.h" |
#include "base/utf_string_conversions.h" |
-#include "third_party/skia/include/core/SkColor.h" |
-#include "views/bubble/bubble_border.h" |
#include "views/bubble/bubble_delegate.h" |
#include "views/bubble/bubble_view.h" |
-#include "views/controls/button/checkbox.h" |
#include "views/controls/button/text_button.h" |
#include "views/controls/label.h" |
#include "views/layout/box_layout.h" |
-#include "views/view.h" |
+#include "views/layout/fill_layout.h" |
#include "views/widget/widget.h" |
namespace examples { |
@@ -21,105 +18,99 @@ namespace examples { |
struct BubbleConfig { |
string16 label; |
SkColor color; |
- gfx::Rect bound; |
+ gfx::Point anchor_point; |
views::BubbleBorder::ArrowLocation arrow; |
+ bool fade_in; |
bool fade_out; |
}; |
-// Create three types of bubbles, one without arrow, one with |
-// arrow, and the third has a fade animation. |
-BubbleConfig kRoundBubbleConfig = { |
- ASCIIToUTF16("RoundBubble"), 0xFFC1B1E1, gfx::Rect(50, 350, 100, 50), |
- views::BubbleBorder::NONE, false }; |
-BubbleConfig kPointyBubbleConfig = { |
- ASCIIToUTF16("PointyBubble"), SK_ColorLTGRAY, gfx::Rect(250, 350, 180, 180), |
- views::BubbleBorder::TOP_LEFT, false }; |
-BubbleConfig kFadeBubbleConfig = { |
- ASCIIToUTF16("FadeBubble"), SK_ColorYELLOW, gfx::Rect(500, 350, 200, 100), |
- views::BubbleBorder::BOTTOM_RIGHT, true }; |
+// Create four types of bubbles, one without arrow, one with an arrow, one |
+// that fades in, and another that fades out and won't close on the escape key. |
+BubbleConfig kRoundConfig = { ASCIIToUTF16("RoundBubble"), 0xFFC1B1E1, |
+ gfx::Point(), views::BubbleBorder::NONE, false, false }; |
+BubbleConfig kArrowConfig = { ASCIIToUTF16("ArrowBubble"), SK_ColorGRAY, |
+ gfx::Point(), views::BubbleBorder::TOP_LEFT, false, false }; |
+BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeInBubble"), SK_ColorYELLOW, |
+ gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, true, false }; |
+BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOutBubble"), SK_ColorWHITE, |
+ gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, false, true }; |
class ExampleBubbleDelegateView : public views::BubbleDelegateView { |
public: |
- ExampleBubbleDelegateView(const BubbleConfig& config, views::Widget* widget) |
- : BubbleDelegateView(widget), config_(config) {} |
+ ExampleBubbleDelegateView(const BubbleConfig& config) |
+ : config_(config) {} |
- virtual views::View* GetContentsView() { return this; } |
+ virtual gfx::Point GetAnchorPoint() const OVERRIDE { |
+ return config_.anchor_point; |
+ } |
- SkColor GetFrameBackgroundColor() { |
- return config_.color; |
+ views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE { |
+ return config_.arrow; |
} |
- gfx::Rect GetBounds() { |
- return config_.bound; |
+ |
+ SkColor GetColor() const OVERRIDE { |
+ return config_.color; |
} |
- views::BubbleBorder::ArrowLocation GetFrameArrowLocation() { |
- return config_.arrow; |
+ protected: |
+ virtual void Init() OVERRIDE { |
+ SetLayoutManager(new views::FillLayout()); |
+ views::Label* label = new views::Label(config_.label); |
+ label->set_border(views::Border::CreateSolidBorder(10, config_.color)); |
+ AddChildView(label); |
} |
private: |
- const BubbleConfig& config_; |
+ const BubbleConfig config_; |
}; |
BubbleExample::BubbleExample(ExamplesMain* main) |
- : ExampleBase(main, "Bubble") { |
-} |
+ : ExampleBase(main, "Bubble") {} |
-BubbleExample::~BubbleExample() { |
-} |
+BubbleExample::~BubbleExample() {} |
void BubbleExample::CreateExampleView(views::View* container) { |
- layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1); |
- container->SetLayoutManager(layout_); |
- round_ = new views::TextButton(this, |
- UTF16ToWideHack(kRoundBubbleConfig.label)); |
- pointy_ = new views::TextButton(this, |
- UTF16ToWideHack(kPointyBubbleConfig.label)); |
- fade_ = new views::TextButton(this, |
- UTF16ToWideHack(kFadeBubbleConfig.label)); |
+ container->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1)); |
+ round_ = new views::TextButton(this, UTF16ToWideHack(kRoundConfig.label)); |
+ arrow_ = new views::TextButton(this, UTF16ToWideHack(kArrowConfig.label)); |
+ fade_in_ = new views::TextButton(this, UTF16ToWideHack(kFadeInConfig.label)); |
+ fade_out_ = new views::TextButton(this, |
+ UTF16ToWideHack(kFadeOutConfig.label)); |
container->AddChildView(round_); |
- container->AddChildView(pointy_); |
- container->AddChildView(fade_); |
+ container->AddChildView(arrow_); |
+ container->AddChildView(fade_in_); |
+ container->AddChildView(fade_out_); |
} |
void BubbleExample::ButtonPressed(views::Button* sender, |
const views::Event& event) { |
- if (sender == round_) { |
- round_bubble_ = AddBubbleButton(kRoundBubbleConfig); |
- round_bubble_->Show(); |
- } else if (sender == pointy_) { |
- pointy_bubble_ = AddBubbleButton(kPointyBubbleConfig); |
- pointy_bubble_->Show(); |
- } else if (sender == fade_) { |
- fade_bubble_ = AddBubbleButton(kFadeBubbleConfig); |
- fade_bubble_->Show(); |
- // Start fade animation. |
- fade_bubble_->client_view()->AsBubbleView()->set_animation_delegate(this); |
- fade_bubble_->client_view()->AsBubbleView()->StartFade(); |
+ BubbleConfig config; |
+ if (sender == round_) |
+ config = kRoundConfig; |
+ else if (sender == arrow_) |
+ config = kArrowConfig; |
+ else if (sender == fade_in_) |
+ config = kFadeInConfig; |
+ else if (sender == fade_out_) |
+ config = kFadeOutConfig; |
+ |
+ config.anchor_point.set_x(sender->width() / 2); |
+ config.anchor_point.set_y(sender->height() / 2); |
+ views::View::ConvertPointToScreen(sender, &config.anchor_point); |
+ |
+ views::Widget* bubble = views::BubbleDelegateView::CreateBubble( |
+ new ExampleBubbleDelegateView(config), example_view()->GetWidget()); |
+ |
+ if (config.fade_in) |
+ bubble->client_view()->AsBubbleView()->StartFade(true); |
+ else |
+ bubble->Show(); |
+ |
+ if (config.fade_out) { |
+ bubble->client_view()->AsBubbleView()->set_close_on_esc(false); |
+ bubble->client_view()->AsBubbleView()->StartFade(false); |
} |
- example_view()->SchedulePaint(); |
-} |
- |
-views::Widget* BubbleExample::AddBubbleButton(const BubbleConfig& config) { |
- // Create a Label. |
- views::Label* bubble_message = new views::Label( |
- ASCIIToUTF16("I am a ") + config.label); |
- bubble_message->SetMultiLine(true); |
- bubble_message->SetAllowCharacterBreak(true); |
- bubble_message->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
- |
- views::Widget* bubble_widget = new views::Widget(); |
- views::Widget::InitParams params(views::Widget::InitParams::TYPE_BUBBLE); |
- params.delegate = new ExampleBubbleDelegateView(config, bubble_widget); |
- params.transparent = true; |
- params.bounds = config.bound; |
- params.parent = example_view()->GetWidget()->GetNativeView(); |
- bubble_widget->Init(params); |
- bubble_widget->client_view()->AsBubbleView()->AddChildView(bubble_message); |
- return bubble_widget; |
-} |
- |
-void BubbleExample::AnimationEnded(const ui::Animation* animation) { |
- PrintStatus("Done Bubble Animation"); |
} |
} // namespace examples |