diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 18:35:52 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 18:35:52 +0000 |
commit | 0d74d4198116eeb86e6dd74f311b4e7980efae6a (patch) | |
tree | 7776df880b07cfa4216e0dd9d3d196e9f332dd4b /ui/aura_shell | |
parent | d55c20ccd50ff15c0cd21b6d2164d0eba5a2e05f (diff) | |
download | chromium_src-0d74d4198116eeb86e6dd74f311b4e7980efae6a.zip chromium_src-0d74d4198116eeb86e6dd74f311b4e7980efae6a.tar.gz chromium_src-0d74d4198116eeb86e6dd74f311b4e7980efae6a.tar.bz2 |
Views Bubble API adjustments and cleanup
Adjust BubbleDelegateView API, add CreateBubble static factory function.
Bubble's arrow anchors with a screen point, can fade in and fade out.
Supporting changes, test updates, misc related cleanup, -275 lines.
BUG=97248,98322,98323
TEST=updated unit tests, views_examples bubbles work.
Review URL: http://codereview.chromium.org/8227003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura_shell')
-rw-r--r-- | ui/aura_shell/examples/bubble.cc | 56 | ||||
-rw-r--r-- | ui/aura_shell/examples/example_factory.h | 6 | ||||
-rw-r--r-- | ui/aura_shell/examples/window_type_launcher.cc | 5 |
3 files changed, 32 insertions, 35 deletions
diff --git a/ui/aura_shell/examples/bubble.cc b/ui/aura_shell/examples/bubble.cc index d0bbbdc..bea8cb8 100644 --- a/ui/aura_shell/examples/bubble.cc +++ b/ui/aura_shell/examples/bubble.cc @@ -7,6 +7,7 @@ #include "views/bubble/bubble_delegate.h" #include "views/bubble/bubble_view.h" #include "views/controls/label.h" +#include "views/layout/fill_layout.h" #include "views/widget/widget.h" namespace aura_shell { @@ -15,54 +16,47 @@ namespace examples { struct BubbleConfig { string16 label; SkColor color; - gfx::Rect bound; + gfx::Point anchor_point; views::BubbleBorder::ArrowLocation arrow; - bool fade_out; }; class ExampleBubbleDelegateView : public views::BubbleDelegateView { public: - ExampleBubbleDelegateView(const BubbleConfig& config, views::Widget* widget) - : BubbleDelegateView(widget), - config_(config) {} - virtual ~ExampleBubbleDelegateView() {} + ExampleBubbleDelegateView(const BubbleConfig& config) + : config_(config) {} - // Overridden from views::BubbleDelegateView - virtual views::View* GetContentsView() OVERRIDE { return this; } - virtual SkColor GetFrameBackgroundColor() OVERRIDE { return config_.color; } - virtual gfx::Rect GetBounds() OVERRIDE { return config_.bound; } - virtual views::BubbleBorder::ArrowLocation GetFrameArrowLocation() OVERRIDE { + virtual gfx::Point GetAnchorPoint() const OVERRIDE { + return config_.anchor_point; + } + + 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_; - - DISALLOW_COPY_AND_ASSIGN(ExampleBubbleDelegateView); }; -void CreateBubble(const BubbleConfig& config, - gfx::NativeWindow parent) { - 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 = parent; - bubble_widget->Init(params); - bubble_widget->client_view()->AsBubbleView()->AddChildView( - new views::Label(ASCIIToUTF16("I am a ") + config.label)); - bubble_widget->Show(); -} - -void CreatePointyBubble(gfx::NativeWindow parent, const gfx::Point& origin) { +void CreatePointyBubble(views::Widget* parent, const gfx::Point& origin) { BubbleConfig config; config.label = ASCIIToUTF16("PointyBubble"); config.color = SK_ColorWHITE; - config.bound = gfx::Rect(origin.x(), origin.y(), 180, 180); + config.anchor_point = origin; config.arrow = views::BubbleBorder::TOP_LEFT; - config.fade_out = false; - CreateBubble(config, parent); + views::Widget* bubble = views::BubbleDelegateView::CreateBubble( + new ExampleBubbleDelegateView(config), parent); + bubble->Show(); } } // namespace examples diff --git a/ui/aura_shell/examples/example_factory.h b/ui/aura_shell/examples/example_factory.h index 7bb34d2..da60715 100644 --- a/ui/aura_shell/examples/example_factory.h +++ b/ui/aura_shell/examples/example_factory.h @@ -12,10 +12,14 @@ namespace gfx { class Point; } +namespace views { +class Widget; +} + namespace aura_shell { namespace examples { -void CreatePointyBubble(gfx::NativeWindow parent, const gfx::Point& origin); +void CreatePointyBubble(views::Widget* parent, const gfx::Point& origin); void CreateLock(); diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc index 2bf5df8..63c0278 100644 --- a/ui/aura_shell/examples/window_type_launcher.cc +++ b/ui/aura_shell/examples/window_type_launcher.cc @@ -123,9 +123,8 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams()); } else if (sender == bubble_button_) { gfx::Point origin = bubble_button_->bounds().origin(); - views::View::ConvertPointToWidget(bubble_button_->parent(), &origin); - origin.Offset(10, bubble_button_->height() - 10); - CreatePointyBubble(GetWidget()->GetNativeWindow(), origin); + views::View::ConvertPointToScreen(bubble_button_->parent(), &origin); + CreatePointyBubble(GetWidget(), origin); } else if (sender == lock_button_) { CreateLock(); } else if (sender == widgets_button_) { |