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

Unified Diff: views/examples/bubble_example.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 side-by-side diff with in-line comments
Download patch
Index: views/examples/bubble_example.cc
diff --git a/views/examples/bubble_example.cc b/views/examples/bubble_example.cc
index ea3173591716de13fd5d40731b492768b5780788..58c19ece4da7170d1447d983024b32ceda498aa8 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,86 @@ namespace examples {
struct BubbleConfig {
string16 label;
SkColor color;
- gfx::Rect bound;
+ gfx::Point arrow_point;
views::BubbleBorder::ArrowLocation arrow;
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 };
+BubbleConfig kRoundBubbleConfig = { ASCIIToUTF16("RoundBubble"), 0xFFC1B1E1,
+ gfx::Point(), views::BubbleBorder::NONE, false };
+BubbleConfig kArrowBubbleConfig = { ASCIIToUTF16("ArrowBubble"), SK_ColorGRAY,
+ gfx::Point(), views::BubbleBorder::TOP_LEFT, false };
+BubbleConfig kFadeBubbleConfig = { ASCIIToUTF16("FadeBubble"), SK_ColorYELLOW,
+ gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, 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; }
-
- SkColor GetFrameBackgroundColor() {
- return config_.color;
- }
- gfx::Rect GetBounds() {
- return config_.bound;
+ virtual gfx::Point GetArrowPoint() const OVERRIDE {
+ return config_.arrow_point;
}
- views::BubbleBorder::ArrowLocation GetFrameArrowLocation() {
+ views::BubbleBorder::ArrowLocation GetArrowLocation() const OVERRIDE {
return config_.arrow;
}
+ SkColor GetColor() const OVERRIDE {
+ return config_.color;
+}
+
+ 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_;
};
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_);
+ container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1));
round_ = new views::TextButton(this,
UTF16ToWideHack(kRoundBubbleConfig.label));
- pointy_ = new views::TextButton(this,
- UTF16ToWideHack(kPointyBubbleConfig.label));
+ arrow_ = new views::TextButton(this,
+ UTF16ToWideHack(kArrowBubbleConfig.label));
fade_ = new views::TextButton(this,
UTF16ToWideHack(kFadeBubbleConfig.label));
container->AddChildView(round_);
- container->AddChildView(pointy_);
+ container->AddChildView(arrow_);
container->AddChildView(fade_);
}
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();
- }
- 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");
+ BubbleConfig config;
+ if (sender == round_)
+ config = kRoundBubbleConfig;
+ else if (sender == arrow_)
+ config = kArrowBubbleConfig;
+ else if (sender == fade_)
+ config = kFadeBubbleConfig;
+
+ config.arrow_point.set_x(sender->width() / 2);
+ config.arrow_point.set_y(sender->height() / 2);
+ views::View::ConvertPointToScreen(sender, &config.arrow_point);
+
+ views::Widget* bubble = views::BubbleDelegateView::ConstructBubble(
+ new ExampleBubbleDelegateView(config), example_view()->GetWidget());
+ bubble->Show();
+ if (config.fade_out)
+ bubble->client_view()->AsBubbleView()->StartFade();
}
} // namespace examples

Powered by Google App Engine
This is Rietveld 408576698