summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 10:09:09 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-12 10:09:09 +0000
commit732975e0695aef927b36b4c1b05406f590f60aff (patch)
tree580d69405af1a2055582a87fd38fb06603b368ab /ui
parente96633903311df7bf3d8c365d7366789ff4aa843 (diff)
downloadchromium_src-732975e0695aef927b36b4c1b05406f590f60aff.zip
chromium_src-732975e0695aef927b36b4c1b05406f590f60aff.tar.gz
chromium_src-732975e0695aef927b36b4c1b05406f590f60aff.tar.bz2
Improve Views Examples BubbleExample, etc.
Add buttons for each shadow, extras for alignment, persistence, and fading. Iterate through bubble colors and arrow locations on each click. Hold [Shift] reverse arrow iteration, [Ctrl] for NONE, and [Alt] for FLOAT. Expose BubbleDelegateView's move_with_anchor accessors; misc cleanup. BUG=NONE TEST=Views Examples has an improved set of examples. TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/13918006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/bubble/bubble_delegate.h49
-rw-r--r--ui/views/examples/bubble_example.cc149
-rw-r--r--ui/views/examples/bubble_example.h9
3 files changed, 109 insertions, 98 deletions
diff --git a/ui/views/bubble/bubble_delegate.h b/ui/views/bubble/bubble_delegate.h
index 407b16ab..ab76fa5 100644
--- a/ui/views/bubble/bubble_delegate.h
+++ b/ui/views/bubble/bubble_delegate.h
@@ -55,9 +55,7 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
void set_close_on_esc(bool close_on_esc) { close_on_esc_ = close_on_esc; }
bool close_on_deactivate() const { return close_on_deactivate_; }
- void set_close_on_deactivate(bool close_on_deactivate) {
- close_on_deactivate_ = close_on_deactivate;
- }
+ void set_close_on_deactivate(bool close) { close_on_deactivate_ = close; }
View* anchor_view() const { return anchor_view_; }
Widget* anchor_widget() const { return anchor_widget_; }
@@ -81,38 +79,34 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
void set_margins(const gfx::Insets& margins) { margins_ = margins; }
const gfx::Insets& anchor_view_insets() const { return anchor_view_insets_; }
- void set_anchor_view_insets(const gfx::Insets& insets) {
- anchor_view_insets_ = insets;
- }
+ void set_anchor_view_insets(const gfx::Insets& i) { anchor_view_insets_ = i; }
gfx::NativeView parent_window() const { return parent_window_; }
void set_parent_window(gfx::NativeView window) { parent_window_ = window; }
bool use_focusless() const { return use_focusless_; }
- void set_use_focusless(bool use_focusless) {
- use_focusless_ = use_focusless;
- }
+ void set_use_focusless(bool focusless) { use_focusless_ = focusless; }
bool accept_events() const { return accept_events_; }
void set_accept_events(bool accept_events) { accept_events_ = accept_events; }
bool border_accepts_events() const { return border_accepts_events_; }
- void set_border_accepts_events(bool accept) {
- border_accepts_events_ = accept;
- }
+ void set_border_accepts_events(bool event) { border_accepts_events_ = event; }
bool adjust_if_offscreen() const { return adjust_if_offscreen_; }
void set_adjust_if_offscreen(bool adjust) { adjust_if_offscreen_ = adjust; }
+ bool move_with_anchor() const { return move_with_anchor_; }
+ void set_move_with_anchor(bool move) { move_with_anchor_ = move; }
+
// Get the arrow's anchor rect in screen space.
virtual gfx::Rect GetAnchorRect();
- // Fade the bubble in or out via Widget transparency.
- // Fade in calls Widget::Show; fade out calls Widget::Close upon completion.
+ // Fade the bubble in or out by animation Widget transparency.
+ // Fade-in calls Widget::Show; fade-out calls Widget::Close upon completion.
void StartFade(bool fade_in);
- // Reset fade and opacity of bubble. Restore the opacity of the
- // bubble to the setting before StartFade() was called.
+ // Restores bubble opacity to its value before StartFade() was called.
void ResetFade();
// Sets the bubble alignment relative to the anchor. This may only be called
@@ -134,20 +128,11 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// Perform view initialization on the contents for bubble sizing.
virtual void Init();
- // Set the anchor view, this (or set_anchor_rect) must be done before
- // calling CreateBubble or Show.
+ // Set the anchor view or rect; set these before CreateBubble or Show.
void set_anchor_view(View* anchor_view) { anchor_view_ = anchor_view; }
- void set_anchor_rect(gfx::Rect anchor_rect) {
- anchor_rect_ = anchor_rect;
- }
+ void set_anchor_rect(const gfx::Rect& rect) { anchor_rect_ = rect; }
- bool move_with_anchor() const { return move_with_anchor_; }
- void set_move_with_anchor(bool move_with_anchor) {
- move_with_anchor_ = move_with_anchor;
- }
-
- // Resizes and potentially moves the Bubble to best accommodate the
- // contents preferred size.
+ // Resize and potentially move the bubble to fit the content's preferred size.
void SizeToContents();
BubbleFrameView* GetBubbleFrameView() const;
@@ -203,15 +188,11 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// The widget hosting the border for this bubble (non-Aura Windows only).
Widget* border_widget_;
- // If true (defaults to false), the bubble does not take user focus upon
- // display.
+ // If true, the bubble does not take focus on display; default is false.
bool use_focusless_;
- // Specifies whether the popup accepts events or lets them pass through.
+ // Specifies whether the bubble (or its border) handles mouse events, etc.
bool accept_events_;
-
- // Specifies whether the bubble border accepts events or lets them pass
- // through.
bool border_accepts_events_;
// If true (defaults to true), the arrow may be mirrored and moved to fit the
diff --git a/ui/views/examples/bubble_example.cc b/ui/views/examples/bubble_example.cc
index d6f7a63..6e2e8ea 100644
--- a/ui/views/examples/bubble_example.cc
+++ b/ui/views/examples/bubble_example.cc
@@ -9,92 +9,119 @@
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
-#include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h"
namespace views {
namespace examples {
-struct BubbleConfig {
- string16 label;
- SkColor color;
- View* anchor_view;
- BubbleBorder::Arrow arrow;
- bool fade_in;
- bool fade_out;
-};
+namespace {
+
+SkColor colors[] = { SK_ColorWHITE, SK_ColorGRAY, SK_ColorCYAN, 0xFFC1B1E1 };
+
+BubbleBorder::Arrow arrows[] = {
+ BubbleBorder::TOP_LEFT, BubbleBorder::TOP_CENTER,
+ BubbleBorder::TOP_RIGHT, BubbleBorder::RIGHT_TOP,
+ BubbleBorder::RIGHT_CENTER, BubbleBorder::RIGHT_BOTTOM,
+ BubbleBorder::BOTTOM_RIGHT, BubbleBorder::BOTTOM_CENTER,
+ BubbleBorder::BOTTOM_LEFT, BubbleBorder::LEFT_BOTTOM,
+ BubbleBorder::LEFT_CENTER, BubbleBorder::LEFT_TOP };
+
+string16 GetArrowName(BubbleBorder::Arrow arrow) {
+ switch (arrow) {
+ case BubbleBorder::TOP_LEFT: return ASCIIToUTF16("TOP_LEFT");
+ case BubbleBorder::TOP_RIGHT: return ASCIIToUTF16("TOP_RIGHT");
+ case BubbleBorder::BOTTOM_LEFT: return ASCIIToUTF16("BOTTOM_LEFT");
+ case BubbleBorder::BOTTOM_RIGHT: return ASCIIToUTF16("BOTTOM_RIGHT");
+ case BubbleBorder::LEFT_TOP: return ASCIIToUTF16("LEFT_TOP");
+ case BubbleBorder::RIGHT_TOP: return ASCIIToUTF16("RIGHT_TOP");
+ case BubbleBorder::LEFT_BOTTOM: return ASCIIToUTF16("LEFT_BOTTOM");
+ case BubbleBorder::RIGHT_BOTTOM: return ASCIIToUTF16("RIGHT_BOTTOM");
+ case BubbleBorder::TOP_CENTER: return ASCIIToUTF16("TOP_CENTER");
+ case BubbleBorder::BOTTOM_CENTER: return ASCIIToUTF16("BOTTOM_CENTER");
+ case BubbleBorder::LEFT_CENTER: return ASCIIToUTF16("LEFT_CENTER");
+ case BubbleBorder::RIGHT_CENTER: return ASCIIToUTF16("RIGHT_CENTER");
+ case BubbleBorder::NONE: return ASCIIToUTF16("NONE");
+ case BubbleBorder::FLOAT: return ASCIIToUTF16("FLOAT");
+ }
+ return ASCIIToUTF16("INVALID");
+}
-// 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("Round"), 0xFFC1B1E1, NULL,
- BubbleBorder::NONE, false, false };
-BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL,
- BubbleBorder::TOP_LEFT, false, false };
-BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL,
- BubbleBorder::BOTTOM_RIGHT, true, false };
-BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL,
- BubbleBorder::LEFT_TOP, false, true };
-
-class ExampleBubbleDelegateView : public BubbleDelegateView {
+class ExampleBubble : public BubbleDelegateView {
public:
- explicit ExampleBubbleDelegateView(const BubbleConfig& config)
- : BubbleDelegateView(config.anchor_view, config.arrow),
- label_(config.label) {
- set_color(config.color);
- }
+ ExampleBubble(View* anchor, BubbleBorder::Arrow arrow)
+ : BubbleDelegateView(anchor, arrow) {}
protected:
virtual void Init() OVERRIDE {
- SetLayoutManager(new FillLayout());
- Label* label = new Label(label_);
- AddChildView(label);
+ SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 20, 20, 0));
+ AddChildView(new Label(GetArrowName(arrow())));
}
private:
- string16 label_;
+ DISALLOW_COPY_AND_ASSIGN(ExampleBubble);
};
+} // namespace
+
BubbleExample::BubbleExample() : ExampleBase("Bubble") {}
BubbleExample::~BubbleExample() {}
void BubbleExample::CreateExampleView(View* container) {
- container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 1));
- round_ = new LabelButton(this, kRoundConfig.label);
- arrow_ = new LabelButton(this, kArrowConfig.label);
- fade_in_ = new LabelButton(this, kFadeInConfig.label);
- fade_out_ = new LabelButton(this, kFadeOutConfig.label);
- container->AddChildView(round_);
- container->AddChildView(arrow_);
+ PrintStatus("Click with optional modifiers: [Ctrl] for set_arrow(NONE), "
+ "[Alt] for set_arrow(FLOAT), or [Shift] to reverse the arrow iteration.");
+ container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, 10));
+ shadow_ = new LabelButton(this, ASCIIToUTF16("Shadow"));
+ container->AddChildView(shadow_);
+ no_shadow_ = new LabelButton(this, ASCIIToUTF16("No Shadow"));
+ container->AddChildView(no_shadow_);
+ big_shadow_ = new LabelButton(this, ASCIIToUTF16("Big Shadow"));
+ container->AddChildView(big_shadow_);
+ small_shadow_ = new LabelButton(this, ASCIIToUTF16("Small Shadow"));
+ container->AddChildView(small_shadow_);
+ align_to_edge_ = new LabelButton(this, ASCIIToUTF16("Align To Edge"));
+ container->AddChildView(align_to_edge_);
+ persistent_ = new LabelButton(this, ASCIIToUTF16("Persistent"));
+ container->AddChildView(persistent_);
+ fade_in_ = new LabelButton(this, ASCIIToUTF16("Fade In"));
container->AddChildView(fade_in_);
- container->AddChildView(fade_out_);
}
void BubbleExample::ButtonPressed(Button* sender, const ui::Event& event) {
- 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_view = sender;
- ExampleBubbleDelegateView* bubble_delegate =
- new ExampleBubbleDelegateView(config);
- BubbleDelegateView::CreateBubble(bubble_delegate);
-
- if (config.fade_in)
- bubble_delegate->StartFade(true);
- else
- bubble_delegate->GetWidget()->Show();
-
- if (config.fade_out) {
- bubble_delegate->set_close_on_esc(false);
- bubble_delegate->StartFade(false);
+ static int arrow_index = 0, color_index = 0;
+ static const int count = arraysize(arrows);
+ arrow_index = (arrow_index + count + (event.IsShiftDown() ? -1 : 1)) % count;
+ BubbleBorder::Arrow arrow = arrows[arrow_index];
+ if (event.IsControlDown())
+ arrow = BubbleBorder::NONE;
+ else if (event.IsAltDown())
+ arrow = BubbleBorder::FLOAT;
+
+ ExampleBubble* bubble = new ExampleBubble(sender, arrow);
+ bubble->set_color(colors[(color_index++) % arraysize(colors)]);
+
+ if (sender == shadow_)
+ bubble->set_shadow(BubbleBorder::SHADOW);
+ else if (sender == no_shadow_)
+ bubble->set_shadow(BubbleBorder::NO_SHADOW);
+ else if (sender == big_shadow_)
+ bubble->set_shadow(BubbleBorder::BIG_SHADOW);
+ else if (sender == small_shadow_)
+ bubble->set_shadow(BubbleBorder::SMALL_SHADOW);
+
+ if (sender == persistent_) {
+ bubble->set_close_on_deactivate(false);
+ bubble->set_move_with_anchor(true);
}
+
+ BubbleDelegateView::CreateBubble(bubble);
+ if (sender == align_to_edge_)
+ bubble->SetAlignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
+
+ if (sender == fade_in_)
+ bubble->StartFade(true);
+ else
+ bubble->GetWidget()->Show();
}
} // namespace examples
diff --git a/ui/views/examples/bubble_example.h b/ui/views/examples/bubble_example.h
index 08e97b9..4ad763a 100644
--- a/ui/views/examples/bubble_example.h
+++ b/ui/views/examples/bubble_example.h
@@ -23,10 +23,13 @@ class BubbleExample : public ExampleBase, public ButtonListener {
private:
virtual void ButtonPressed(Button* sender, const ui::Event& event) OVERRIDE;
- Button* round_;
- Button* arrow_;
+ Button* shadow_;
+ Button* no_shadow_;
+ Button* big_shadow_;
+ Button* small_shadow_;
+ Button* align_to_edge_;
+ Button* persistent_;
Button* fade_in_;
- Button* fade_out_;
DISALLOW_COPY_AND_ASSIGN(BubbleExample);
};