summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 19:54:34 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 19:54:34 +0000
commit0a00ea33d6feec80e32acc4ff28ec6bcbf46aaf3 (patch)
tree957a315830daa8dc2c32700b738de17826a08222 /views
parent8a63cdc2e561499235c646d18efa0371064cec51 (diff)
downloadchromium_src-0a00ea33d6feec80e32acc4ff28ec6bcbf46aaf3.zip
chromium_src-0a00ea33d6feec80e32acc4ff28ec6bcbf46aaf3.tar.gz
chromium_src-0a00ea33d6feec80e32acc4ff28ec6bcbf46aaf3.tar.bz2
Move BubbleView logic into BubbleDelegateView.
Add customization ctor; override GetInitiallyFocusedView. BUG=97248,98322,98323 TEST=views_examples bubbles work as before. Review URL: http://codereview.chromium.org/8349015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106546 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/bubble/bubble_delegate.cc74
-rw-r--r--views/bubble/bubble_delegate.h42
-rw-r--r--views/bubble/bubble_view.cc69
-rw-r--r--views/bubble/bubble_view.h54
-rw-r--r--views/examples/bubble_example.cc32
-rw-r--r--views/views.gyp2
6 files changed, 121 insertions, 152 deletions
diff --git a/views/bubble/bubble_delegate.cc b/views/bubble/bubble_delegate.cc
index e777e58..8d8228b 100644
--- a/views/bubble/bubble_delegate.cc
+++ b/views/bubble/bubble_delegate.cc
@@ -4,12 +4,35 @@
#include "views/bubble/bubble_delegate.h"
+#include "ui/base/animation/slide_animation.h"
#include "views/bubble/bubble_frame_view.h"
-#include "views/bubble/bubble_view.h"
#include "views/widget/widget.h"
+// The duration of the fade animation in milliseconds.
+static const int kHideFadeDurationMS = 1000;
+
namespace views {
+BubbleDelegateView::BubbleDelegateView()
+ : WidgetDelegateView(),
+ close_on_esc_(true),
+ arrow_location_(BubbleBorder::TOP_LEFT),
+ color_(SK_ColorWHITE) {
+ AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
+}
+
+BubbleDelegateView::BubbleDelegateView(
+ const gfx::Point& anchor_point,
+ BubbleBorder::ArrowLocation arrow_location,
+ const SkColor& color)
+ : WidgetDelegateView(),
+ close_on_esc_(true),
+ anchor_point_(anchor_point),
+ arrow_location_(arrow_location),
+ color_(color) {
+ AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
+}
+
BubbleDelegateView::~BubbleDelegateView() {}
// static
@@ -28,12 +51,16 @@ Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate,
return bubble_widget;
}
+View* BubbleDelegateView::GetInitiallyFocusedView() {
+ return this;
+}
+
View* BubbleDelegateView::GetContentsView() {
return this;
}
ClientView* BubbleDelegateView::CreateClientView(Widget* widget) {
- return new BubbleView(widget, GetContentsView());
+ return new ClientView(widget, GetContentsView());
}
NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() {
@@ -43,19 +70,56 @@ NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() {
}
gfx::Point BubbleDelegateView::GetAnchorPoint() const {
- return gfx::Point();
+ return anchor_point_;
}
BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const {
- return BubbleBorder::TOP_LEFT;
+ return arrow_location_;
}
SkColor BubbleDelegateView::GetColor() const {
- return SK_ColorWHITE;
+ return color_;
}
void BubbleDelegateView::Init() {}
+void BubbleDelegateView::StartFade(bool fade_in) {
+ fade_animation_.reset(new ui::SlideAnimation(this));
+ fade_animation_->SetSlideDuration(kHideFadeDurationMS);
+ fade_animation_->Reset(fade_in ? 0.0 : 1.0);
+ if (fade_in) {
+ GetWidget()->SetOpacity(0);
+ GetWidget()->Show();
+ fade_animation_->Show();
+ } else {
+ fade_animation_->Hide();
+ }
+}
+
+bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) {
+ if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
+ return false;
+ if (fade_animation_.get())
+ fade_animation_->Reset();
+ GetWidget()->Close();
+ return true;
+}
+
+void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) {
+ DCHECK_EQ(animation, fade_animation_.get());
+ bool closed = fade_animation_->GetCurrentValue() == 0;
+ fade_animation_->Reset();
+ if (closed)
+ GetWidget()->Close();
+}
+
+void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) {
+ DCHECK_EQ(animation, fade_animation_.get());
+ DCHECK(fade_animation_->is_animating());
+ GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255);
+ SchedulePaint();
+}
+
const BubbleView* BubbleDelegateView::GetBubbleView() const {
return GetWidget()->client_view()->AsBubbleView();
}
diff --git a/views/bubble/bubble_delegate.h b/views/bubble/bubble_delegate.h
index 5b2c9c3..2e1d78e 100644
--- a/views/bubble/bubble_delegate.h
+++ b/views/bubble/bubble_delegate.h
@@ -6,9 +6,14 @@
#define VIEWS_BUBBLE_BUBBLE_DELEGATE_H_
#pragma once
+#include "ui/base/animation/animation_delegate.h"
#include "views/bubble/bubble_border.h"
#include "views/widget/widget_delegate.h"
+namespace ui {
+class SlideAnimation;
+} // namespace ui
+
namespace views {
class BubbleFrameView;
@@ -18,8 +23,13 @@ class BubbleView;
// BubbleDelegateView itself is the client's contents view.
//
///////////////////////////////////////////////////////////////////////////////
-class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView {
+class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
+ public ui::AnimationDelegate {
public:
+ BubbleDelegateView();
+ BubbleDelegateView(const gfx::Point& anchor_point,
+ BubbleBorder::ArrowLocation arrow_location,
+ const SkColor& color);
virtual ~BubbleDelegateView();
// Create a bubble Widget from the argument BubbleDelegateView.
@@ -27,10 +37,14 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView {
Widget* parent_widget);
// WidgetDelegate overrides:
+ virtual View* GetInitiallyFocusedView() OVERRIDE;
virtual View* GetContentsView() OVERRIDE;
virtual ClientView* CreateClientView(Widget* widget) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
+ bool close_on_esc() const { return close_on_esc_; }
+ void set_close_on_esc(bool close_on_esc) { close_on_esc_ = close_on_esc; }
+
// Get the arrow's anchor point in screen space.
virtual gfx::Point GetAnchorPoint() const;
@@ -40,16 +54,42 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView {
// Get the color used for the background and border.
virtual SkColor GetColor() const;
+ // Fade the bubble in or out via Widget transparency.
+ // Fade in calls Widget::Show; fade out calls Widget::Close upon completion.
+ void StartFade(bool fade_in);
+
protected:
+ // View overrides:
+ virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
+
// Perform view initialization on the contents for bubble sizing.
virtual void Init();
private:
+ // ui::AnimationDelegate overrides:
+ virtual void AnimationEnded(const ui::Animation* animation);
+ virtual void AnimationProgressed(const ui::Animation* animation);
+
const BubbleView* GetBubbleView() const;
const BubbleFrameView* GetBubbleFrameView() const;
// Get bubble bounds from the anchor point and client view's preferred size.
gfx::Rect GetBubbleBounds();
+
+ // Fade animation for bubble.
+ scoped_ptr<ui::SlideAnimation> fade_animation_;
+
+ // Should this bubble close on the escape key?
+ bool close_on_esc_;
+
+ // The screen point where this bubble's arrow is anchored.
+ gfx::Point anchor_point_;
+
+ // The arrow's location on the bubble.
+ BubbleBorder::ArrowLocation arrow_location_;
+
+ // The background color of the bubble.
+ SkColor color_;
};
} // namespace views
diff --git a/views/bubble/bubble_view.cc b/views/bubble/bubble_view.cc
deleted file mode 100644
index 85a271f..0000000
--- a/views/bubble/bubble_view.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "views/bubble/bubble_view.h"
-
-#include "ui/base/animation/slide_animation.h"
-#include "views/bubble/bubble_border.h"
-#include "views/widget/widget.h"
-
-// The duration of the fade animation in milliseconds.
-static const int kHideFadeDurationMS = 1000;
-
-namespace views {
-
-BubbleView::BubbleView(Widget* owner, View* contents_view)
- : ClientView(owner, contents_view),
- close_on_esc_(true) {
- AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0));
-}
-
-BubbleView::~BubbleView() {}
-
-BubbleView* BubbleView::AsBubbleView() {
- return this;
-}
-
-const BubbleView* BubbleView::AsBubbleView() const {
- return this;
-}
-
-void BubbleView::StartFade(bool fade_in) {
- fade_animation_.reset(new ui::SlideAnimation(this));
- fade_animation_->SetSlideDuration(kHideFadeDurationMS);
- fade_animation_->Reset(fade_in ? 0.0 : 1.0);
- if (fade_in) {
- GetWidget()->SetOpacity(0);
- GetWidget()->Show();
- fade_animation_->Show();
- } else {
- fade_animation_->Hide();
- }
-}
-
-bool BubbleView::AcceleratorPressed(const Accelerator& accelerator) {
- if (!close_on_esc_ || accelerator.key_code() != ui::VKEY_ESCAPE)
- return false;
- if (fade_animation_.get())
- fade_animation_->Reset();
- GetWidget()->Close();
- return true;
-}
-
-void BubbleView::AnimationEnded(const ui::Animation* animation) {
- DCHECK_EQ(animation, fade_animation_.get());
- bool closed = fade_animation_->GetCurrentValue() == 0;
- fade_animation_->Reset();
- if (closed)
- GetWidget()->Close();
-}
-
-void BubbleView::AnimationProgressed(const ui::Animation* animation) {
- DCHECK_EQ(animation, fade_animation_.get());
- DCHECK(fade_animation_->is_animating());
- GetWidget()->SetOpacity(fade_animation_->GetCurrentValue() * 255);
- SchedulePaint();
-}
-
-} // namespace views
diff --git a/views/bubble/bubble_view.h b/views/bubble/bubble_view.h
deleted file mode 100644
index 900eb0f..0000000
--- a/views/bubble/bubble_view.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef VIEWS_BUBBLE_BUBBLE_VIEW_H_
-#define VIEWS_BUBBLE_BUBBLE_VIEW_H_
-#pragma once
-
-#include "ui/base/animation/animation_delegate.h"
-#include "views/accelerator.h"
-#include "views/window/client_view.h"
-
-namespace ui {
-class SlideAnimation;
-} // namespace ui
-
-namespace views {
-
-class VIEWS_EXPORT BubbleView : public ClientView,
- public ui::AnimationDelegate {
- public:
- BubbleView(Widget* widget, View* contents_view);
- virtual ~BubbleView();
-
- // ClientView overrides:
- virtual BubbleView* AsBubbleView() OVERRIDE;
- virtual const BubbleView* AsBubbleView() const OVERRIDE;
-
- void set_close_on_esc(bool close_on_esc) { close_on_esc_ = close_on_esc; }
-
- // Starts a fade animation, fade out closes the widget upon completion.
- void StartFade(bool fade_in);
-
- protected:
- // View overrides:
- virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE;
-
- private:
- // ui::AnimationDelegate overrides:
- virtual void AnimationEnded(const ui::Animation* animation);
- virtual void AnimationProgressed(const ui::Animation* animation);
-
- // Fade animation for bubble.
- scoped_ptr<ui::SlideAnimation> fade_animation_;
-
- // Should this bubble close on the escape key?
- bool close_on_esc_;
-
- DISALLOW_COPY_AND_ASSIGN(BubbleView);
-};
-
-} // namespace views
-
-#endif // VIEWS_BUBBLE_BUBBLE_VIEW_H_
diff --git a/views/examples/bubble_example.cc b/views/examples/bubble_example.cc
index 94e2605..f99155b 100644
--- a/views/examples/bubble_example.cc
+++ b/views/examples/bubble_example.cc
@@ -6,7 +6,6 @@
#include "base/utf_string_conversions.h"
#include "views/bubble/bubble_delegate.h"
-#include "views/bubble/bubble_view.h"
#include "views/controls/button/text_button.h"
#include "views/controls/label.h"
#include "views/layout/box_layout.h"
@@ -38,30 +37,19 @@ BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOutBubble"), SK_ColorWHITE,
class ExampleBubbleDelegateView : public views::BubbleDelegateView {
public:
ExampleBubbleDelegateView(const BubbleConfig& config)
- : config_(config) {}
-
- 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;
- }
+ : BubbleDelegateView(config.anchor_point, config.arrow, config.color),
+ label_(config.label) {}
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));
+ views::Label* label = new views::Label(label_);
+ label->set_border(views::Border::CreateSolidBorder(10, GetColor()));
AddChildView(label);
}
private:
- const BubbleConfig config_;
+ string16 label_;
};
BubbleExample::BubbleExample(ExamplesMain* main)
@@ -98,17 +86,19 @@ void BubbleExample::ButtonPressed(views::Button* sender,
config.anchor_point.set_y(sender->height() / 2);
views::View::ConvertPointToScreen(sender, &config.anchor_point);
+ ExampleBubbleDelegateView* bubble_delegate =
+ new ExampleBubbleDelegateView(config);
views::Widget* bubble = views::BubbleDelegateView::CreateBubble(
- new ExampleBubbleDelegateView(config), example_view()->GetWidget());
+ bubble_delegate, example_view()->GetWidget());
if (config.fade_in)
- bubble->client_view()->AsBubbleView()->StartFade(true);
+ bubble_delegate->StartFade(true);
else
bubble->Show();
if (config.fade_out) {
- bubble->client_view()->AsBubbleView()->set_close_on_esc(false);
- bubble->client_view()->AsBubbleView()->StartFade(false);
+ bubble_delegate->set_close_on_esc(false);
+ bubble_delegate->StartFade(false);
}
}
diff --git a/views/views.gyp b/views/views.gyp
index f9f9616..103c7d2 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -67,8 +67,6 @@
'bubble/bubble_delegate.h',
'bubble/bubble_frame_view.cc',
'bubble/bubble_frame_view.h',
- 'bubble/bubble_view.cc',
- 'bubble/bubble_view.h',
'context_menu_controller.h',
'controls/button/button.cc',
'controls/button/button.h',