| Index: ash/wm/window_maximize.cc
|
| diff --git a/ash/wm/window_maximize.cc b/ash/wm/window_maximize.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b3fda9328c063bc8997de8bb147aef69dc328246
|
| --- /dev/null
|
| +++ b/ash/wm/window_maximize.cc
|
| @@ -0,0 +1,716 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +// Needs to be included first to get the enum resolved.
|
| +#include "ash/wm/workspace/frame_maximize_button.h"
|
| +#include "ash/wm/window_maximize.h"
|
| +
|
| +#include "ash/shell.h"
|
| +#include "ash/shell_window_ids.h"
|
| +#include "ash/wm/window_animations.h"
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "base/timer.h"
|
| +#include "grit/ash_strings.h"
|
| +#include "grit/ui_resources.h"
|
| +#include "ui/aura/aura_switches.h"
|
| +#include "ui/base/ui_base_switches.h"
|
| +#include "ui/aura/event.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/screen.h"
|
| +#include "ui/views/bubble/bubble_delegate.h"
|
| +#include "ui/views/bubble/bubble_frame_view.h"
|
| +#include "ui/views/controls/button/button.h"
|
| +#include "ui/views/controls/button/custom_button.h"
|
| +#include "ui/views/controls/label.h"
|
| +#include "ui/views/events/event.h"
|
| +#include "ui/views/layout/box_layout.h"
|
| +#include "ui/views/radial_menu/radial_menu_views.h"
|
| +
|
| +namespace {
|
| +
|
| +// The command codes returned from the radial menu.
|
| +enum RadialMenuCommands {
|
| + RADIAL_MENU_NONE = 0,
|
| + RADIAL_MENU_RIGHT,
|
| + RADIAL_MENU_MINIMIZE,
|
| + RADIAL_MENU_LEFT
|
| +};
|
| +
|
| +// Bubble constants
|
| +const int kMaximumBubbleWidth = 200;
|
| +const int kArrowOffset = 10;
|
| +
|
| +// The spacing between two buttons.
|
| +const int kLayoutSpacing = 1;
|
| +
|
| +const int kAnimationDurationForPopupMS = 200;
|
| +
|
| +// The background color
|
| +const SkColor kBubbleBackgroundColor = 0xf2141414;
|
| +
|
| +// The text color within the bubble
|
| +const SkColor kBubbleTextColor = 0xffffffff;
|
| +
|
| +// The line width of the bubble.
|
| +const int kLineHeight = 1;
|
| +
|
| +// The pixel dimensions of the arrow
|
| +const int kArrowHeight = 10;
|
| +const int kArrowWidth = 20;
|
| +
|
| +// The delay of the bubble appearance.
|
| +const int kBubbleAppearanceDelay = 200; // msec
|
| +
|
| +// The active area behind a segment in a radial menu (in segment widths):
|
| +// In case of hover the user wants to cancel out when getting reasonably far
|
| +// away from the menu.
|
| +const int kHoverRadialMenuExtension = 3;
|
| +// In case of dragging the menu extends till eternity.
|
| +const int kDragRadialMenuExtension = 10000;
|
| +
|
| +class MaximizeBubbleBorder : public views::BubbleBorder {
|
| + public:
|
| + MaximizeBubbleBorder(views::View* owner,
|
| + views::View* anchor)
|
| + : views::BubbleBorder(views::BubbleBorder::TOP_RIGHT,
|
| + views::BubbleBorder::NO_SHADOW),
|
| + owner_(owner),
|
| + anchor_(anchor) {
|
| + set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
|
| + }
|
| +
|
| + virtual ~MaximizeBubbleBorder() {}
|
| +
|
| + // Overridden from views::BubbleBorder to match the design specs.
|
| + virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
|
| + const gfx::Size& contents_size) const OVERRIDE {
|
| + gfx::Size border_size(contents_size);
|
| + gfx::Insets insets;
|
| + GetInsets(&insets);
|
| + border_size.Enlarge(insets.width(), insets.height());
|
| +
|
| + // Position the bubble to center the box on the anchor.
|
| + int x = -insets.left() -
|
| + (border_size.width() - anchor_->width() - kArrowWidth) / 2;
|
| + // Position the bubble under the anchor, overlapping the arrow with it.
|
| + int y = anchor_->height() - insets.top();
|
| +
|
| + gfx::Point view_topleft(x, y);
|
| + views::View::ConvertPointToScreen(anchor_, &view_topleft);
|
| +
|
| + return gfx::Rect(view_topleft.x(), view_topleft.y(),
|
| + border_size.width(), border_size.height());
|
| + }
|
| +
|
| + // Overridden from views::Border
|
| + virtual void Paint(const views::View& view,
|
| + gfx::Canvas* canvas) const OVERRIDE {
|
| + gfx::Insets inset;
|
| + GetInsets(&inset);
|
| +
|
| + // Draw the border line around everything.
|
| + int y = inset.top();
|
| + // Top
|
| + canvas->FillRect(gfx::Rect(inset.left(),
|
| + y - kLineHeight,
|
| + owner_->width(),
|
| + kLineHeight),
|
| + kBubbleBackgroundColor);
|
| + // Bottom
|
| + canvas->FillRect(gfx::Rect(inset.left(),
|
| + y + owner_->height(),
|
| + owner_->width(),
|
| + kLineHeight),
|
| + kBubbleBackgroundColor);
|
| + // Left
|
| + canvas->FillRect(gfx::Rect(inset.left() - kLineHeight,
|
| + y - kLineHeight,
|
| + kLineHeight,
|
| + owner_->height() + 2 * kLineHeight),
|
| + kBubbleBackgroundColor);
|
| + // Right
|
| + canvas->FillRect(gfx::Rect(inset.left() + owner_->width(),
|
| + y - kLineHeight,
|
| + kLineHeight,
|
| + owner_->height() + 2 * kLineHeight),
|
| + kBubbleBackgroundColor);
|
| +
|
| + // Draw the arrow afterwards covering the border.
|
| + SkPath path;
|
| + path.incReserve(4);
|
| + // The center of the tip should be in the middle of the button.
|
| + int tip_x = inset.left() + owner_->width() / 2;
|
| + int left_base_x = tip_x - kArrowWidth / 2;
|
| + int left_base_y = y;
|
| + int tip_y = left_base_y - kArrowHeight;
|
| + path.moveTo(SkIntToScalar(left_base_x), SkIntToScalar(left_base_y));
|
| + path.lineTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y));
|
| + path.lineTo(SkIntToScalar(left_base_x + kArrowWidth),
|
| + SkIntToScalar(left_base_y));
|
| +
|
| + SkPaint paint;
|
| + paint.setStyle(SkPaint::kFill_Style);
|
| + paint.setColor(kBubbleBackgroundColor);
|
| + canvas->DrawPath(path, paint);
|
| + }
|
| +
|
| + private:
|
| + views::View* owner_;
|
| + views::View* anchor_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MaximizeBubbleBorder);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +namespace ash {
|
| +
|
| +// The image button gets overridden to be able to capture mouse hover events.
|
| +class MaximizeBubble::BubbleMenuButton : public views::ImageButton {
|
| + public:
|
| + explicit BubbleMenuButton(MaximizeBubble::BubbleContentsButtonRow* listener);
|
| + virtual ~BubbleMenuButton() {};
|
| +
|
| + // CustomButton overrides:
|
| + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
|
| + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
|
| +
|
| + private:
|
| + // The creating class which needs to get notified in case of a hover event.
|
| + MaximizeBubble::BubbleContentsButtonRow* owner_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BubbleMenuButton);
|
| +};
|
| +
|
| +// A class that creates all buttons and put them into a view.
|
| +class MaximizeBubble::BubbleContentsButtonRow : public views::View,
|
| + public views::ButtonListener {
|
| + public:
|
| + explicit BubbleContentsButtonRow(MaximizeBubble* bubble)
|
| + : bubble_(bubble),
|
| + left_button_(NULL),
|
| + minimize_button_(NULL),
|
| + right_button_(NULL) {
|
| + SetLayoutManager(new views::BoxLayout(
|
| + views::BoxLayout::kHorizontal, 0, 0, kLayoutSpacing));
|
| + set_background(
|
| + views::Background::CreateSolidBackground(kBubbleBackgroundColor));
|
| +
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| + left_button_ = new MaximizeBubble::BubbleMenuButton(this);
|
| + left_button_->SetImage(views::CustomButton::BS_NORMAL,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
|
| + left_button_->SetImage(views::CustomButton::BS_HOT,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
|
| + left_button_->SetImage(views::CustomButton::BS_PUSHED,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P));
|
| + AddChildView(left_button_);
|
| +
|
| + minimize_button_ = new MaximizeBubble::BubbleMenuButton(this);
|
| + minimize_button_->SetImage(views::CustomButton::BS_NORMAL,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
|
| + minimize_button_->SetImage(views::CustomButton::BS_HOT,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
|
| + minimize_button_->SetImage(views::CustomButton::BS_PUSHED,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P));
|
| + AddChildView(minimize_button_);
|
| +
|
| + right_button_ = new MaximizeBubble::BubbleMenuButton(this);
|
| + right_button_->SetImage(views::CustomButton::BS_NORMAL,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
|
| + right_button_->SetImage(views::CustomButton::BS_HOT,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
|
| + right_button_->SetImage(views::CustomButton::BS_PUSHED,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P));
|
| + AddChildView(right_button_);
|
| + }
|
| +
|
| + virtual ~BubbleContentsButtonRow() {}
|
| +
|
| + // Overridden from ButtonListener.
|
| + virtual void ButtonPressed(views::Button* sender,
|
| + const views::Event& event) OVERRIDE {
|
| + if (sender == left_button_)
|
| + bubble_->OnButtonClicked(FrameMaximizeButton::SNAP_LEFT);
|
| + if (sender == minimize_button_)
|
| + bubble_->OnButtonClicked(FrameMaximizeButton::SNAP_MINIMIZE);
|
| + if (sender == right_button_)
|
| + bubble_->OnButtonClicked(FrameMaximizeButton::SNAP_RIGHT);
|
| + }
|
| +
|
| + // Called from BubbleMenuButton.
|
| + void ButtonHovered(MaximizeBubble::BubbleMenuButton* sender) {
|
| + if (sender == left_button_)
|
| + bubble_->OnButtonHover(FrameMaximizeButton::SNAP_LEFT);
|
| + else if (sender == minimize_button_)
|
| + bubble_->OnButtonHover(FrameMaximizeButton::SNAP_MINIMIZE);
|
| + else if (sender == right_button_)
|
| + bubble_->OnButtonHover(FrameMaximizeButton::SNAP_RIGHT);
|
| + else
|
| + bubble_->OnButtonHover(FrameMaximizeButton::SNAP_NONE);
|
| + }
|
| +
|
| + private:
|
| + // The owning object which gets notifications.
|
| + MaximizeBubble* bubble_;
|
| +
|
| + // The created buttons for our menu.
|
| + MaximizeBubble::BubbleMenuButton* left_button_;
|
| + MaximizeBubble::BubbleMenuButton* minimize_button_;
|
| + MaximizeBubble::BubbleMenuButton* right_button_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BubbleContentsButtonRow);
|
| +};
|
| +
|
| +MaximizeBubble::BubbleMenuButton::BubbleMenuButton(
|
| + MaximizeBubble::BubbleContentsButtonRow* listener)
|
| + : views::ImageButton(listener),
|
| + owner_(listener) {}
|
| +
|
| +void MaximizeBubble::BubbleMenuButton::OnMouseEntered(
|
| + const views::MouseEvent& event) OVERRIDE {
|
| + owner_->ButtonHovered(this);
|
| + views::ImageButton::OnMouseEntered(event);
|
| +}
|
| +
|
| +void MaximizeBubble::BubbleMenuButton::OnMouseExited(
|
| + const views::MouseEvent& event) OVERRIDE {
|
| + owner_->ButtonHovered(NULL);
|
| + views::ImageButton::OnMouseExited(event);
|
| +}
|
| +
|
| +// A class which creates the content of the bubble: The buttons, and the label.
|
| +class MaximizeBubble::BubbleContentsView : public views::View {
|
| + public:
|
| + explicit BubbleContentsView(MaximizeBubble* bubble)
|
| + : bubble_(bubble) {
|
| + SetLayoutManager(new views::BoxLayout(
|
| + views::BoxLayout::kVertical, 0, 0, kLayoutSpacing));
|
| + set_background(
|
| + views::Background::CreateSolidBackground(kBubbleBackgroundColor));
|
| +
|
| + buttons_view_ = new BubbleContentsButtonRow(bubble);
|
| + AddChildView(buttons_view_);
|
| +
|
| + label_view_ = new views::Label();
|
| + SetMenuState(FrameMaximizeButton::SNAP_NONE);
|
| + label_view_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
|
| + label_view_->SetBackgroundColor(kBubbleBackgroundColor);
|
| + label_view_->SetEnabledColor(kBubbleTextColor);
|
| + AddChildView(label_view_);
|
| + }
|
| +
|
| + virtual ~BubbleContentsView() {}
|
| +
|
| + // Set the label content to reflect the currently selected |snap_type|.
|
| + // This function can be executed through the frame maximize button as well as
|
| + // through hover operations.
|
| + void SetMenuState(FrameMaximizeButton::SnapType snap_type) {
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| + switch (snap_type) {
|
| + case FrameMaximizeButton::SNAP_LEFT:
|
| + label_view_->SetText(rb.GetLocalizedString(IDS_ASH_SNAP_WINDOW_LEFT));
|
| + return;
|
| + case FrameMaximizeButton::SNAP_RIGHT:
|
| + label_view_->SetText(rb.GetLocalizedString(IDS_ASH_SNAP_WINDOW_RIGHT));
|
| + return;
|
| + case FrameMaximizeButton::SNAP_MAXIMIZE:
|
| + DCHECK(!bubble_->is_maximized());
|
| + label_view_->SetText(rb.GetLocalizedString(IDS_ASH_MAXIMIZE_WINDOW));
|
| + return;
|
| + case FrameMaximizeButton::SNAP_MINIMIZE:
|
| + label_view_->SetText(rb.GetLocalizedString(IDS_ASH_MINIMIZE_WINDOW));
|
| + return;
|
| + case FrameMaximizeButton::SNAP_RESTORE:
|
| + DCHECK(bubble_->is_maximized());
|
| + label_view_->SetText(rb.GetLocalizedString(IDS_ASH_RESTORE_WINDOW));
|
| + return;
|
| + default:
|
| + // If nothing is selected, we automatically select the click operation.
|
| + label_view_->SetText(rb.GetLocalizedString(
|
| + bubble_->is_maximized() ? IDS_ASH_RESTORE_WINDOW :
|
| + IDS_ASH_MAXIMIZE_WINDOW));
|
| + return;
|
| + }
|
| + }
|
| +
|
| + private:
|
| + // The owning class.
|
| + MaximizeBubble* bubble_;
|
| +
|
| + // The object which owns all the buttons.
|
| + BubbleContentsButtonRow* buttons_view_;
|
| +
|
| + // The label object which shows the user the selected action.
|
| + views::Label* label_view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BubbleContentsView);
|
| +};
|
| +
|
| +// The class which creates and manages the bubble menu element.
|
| +// It creates a "bubble border" and the content accordingly.
|
| +// Note: Since the SnapSizer will show animations on top of the maximize button
|
| +// this menu gets creates as a separate window and the SnapSizer will be
|
| +// created underneath this window.
|
| +class MaximizeBubble::Bubble : public views::BubbleDelegateView {
|
| + public:
|
| + explicit Bubble(MaximizeBubble* bubble)
|
| + : views::BubbleDelegateView(bubble->frame_maximize_button(),
|
| + views::BubbleBorder::TOP_RIGHT),
|
| + bubble_(bubble),
|
| + bubble_widget_(NULL),
|
| + contents_view_(NULL) {
|
| + set_margins(gfx::Insets());
|
| +
|
| + // The window needs to be owned by the root so that the SnapSizer does not
|
| + // cover it upon animation.
|
| + aura::Window* parent = Shell::GetContainer(
|
| + Shell::GetActiveRootWindow(),
|
| + internal::kShellWindowId_LauncherContainer);
|
| + set_parent_window(parent);
|
| +
|
| + set_notify_enter_exit_on_child(true);
|
| + set_try_mirroring_arrow(false);
|
| + SetPaintToLayer(true);
|
| + set_color(kBubbleBackgroundColor);
|
| + set_close_on_deactivate(false);
|
| + set_background(
|
| + views::Background::CreateSolidBackground(kBubbleBackgroundColor));
|
| +
|
| + SetLayoutManager(new views::BoxLayout(
|
| + views::BoxLayout::kVertical, 0, 0, kLayoutSpacing));
|
| +
|
| + contents_view_ = new BubbleContentsView(bubble);
|
| + AddChildView(contents_view_);
|
| +
|
| + // Note that the returned widget has an observer which points to our
|
| + // functions.
|
| + bubble_widget_ = views::BubbleDelegateView::CreateBubble(this);
|
| +
|
| + SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
|
| + bubble_widget_->non_client_view()->frame_view()->set_background(NULL);
|
| +
|
| + MaximizeBubbleBorder* bubble_border = new MaximizeBubbleBorder(
|
| + this, anchor_view());
|
| + GetBubbleFrameView()->SetBubbleBorder(bubble_border);
|
| + GetBubbleFrameView()->set_background(NULL);
|
| +
|
| + // Recalculate size with new border.
|
| + SizeToContents();
|
| +
|
| + // Setup animation.
|
| + ash::SetWindowVisibilityAnimationType(
|
| + bubble_widget_->GetNativeWindow(),
|
| + ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
|
| + ash::SetWindowVisibilityAnimationTransition(
|
| + bubble_widget_->GetNativeWindow(),
|
| + ash::ANIMATE_BOTH);
|
| + ash::SetWindowVisibilityAnimationDuration(
|
| + bubble_widget_->GetNativeWindow(),
|
| + base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
|
| +
|
| + Show();
|
| + }
|
| +
|
| + virtual ~Bubble() {
|
| + if (bubble_widget_) {
|
| + bubble_widget_->RemoveObserver(this);
|
| + anchor_widget()->RemoveObserver(this);
|
| + bubble_widget_->Close();
|
| + bubble_widget_ = NULL;
|
| + }
|
| + }
|
| +
|
| + // The window of the menu under which the SnapSizer will get created.
|
| + aura::Window* GetMenuWindow() {
|
| + return bubble_widget_ ? bubble_widget_->GetNativeWindow() : NULL;
|
| + }
|
| +
|
| + // Overridden from views::BubbleDelegateView.
|
| + virtual gfx::Rect GetAnchorRect() const OVERRIDE {
|
| + gfx::Rect anchor_rect =
|
| + bubble_->frame_maximize_button()->GetBoundsInScreen();
|
| + return anchor_rect;
|
| + }
|
| +
|
| + // Overridden from View
|
| + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE {
|
| + // When we leave the bubble, we might be still be in gesture mode or over
|
| + // the maximize button. So only close if none of the other cases apply.
|
| + if (!bubble_->frame_maximize_button()->is_snap_enabled()) {
|
| + gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint();
|
| + if (!bubble_->frame_maximize_button()->GetBoundsInScreen().Contains(
|
| + screen_location))
|
| + bubble_->Close();
|
| + }
|
| + }
|
| +
|
| + virtual void OnClickedOutsideView() OVERRIDE {
|
| + // Don't destroy the menu when the click happened on the frame maximize
|
| + // button.
|
| + if (!bubble_->frame_maximize_button()->is_snap_enabled())
|
| + bubble_->Close(); // Will destroy |this|.
|
| + }
|
| +
|
| + // Overridden from views::View.
|
| + virtual gfx::Size GetPreferredSize() OVERRIDE {
|
| + return contents_view_->GetPreferredSize();
|
| + }
|
| +
|
| + // Overridden from views::Widget::Observer.
|
| + virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE {
|
| + if (bubble_widget_) {
|
| + CHECK_EQ(bubble_widget_, widget);
|
| + bubble_widget_ = NULL;
|
| + bubble_->Close(); // Will destroy |this|.
|
| + }
|
| + }
|
| +
|
| + // Called from the owning class to indicate that the menu should get
|
| + // destroyed.
|
| + virtual void Close() {
|
| + if (bubble_widget_) {
|
| + bubble_widget_->Close();
|
| + bubble_widget_ = NULL;
|
| + }
|
| + bubble_->Close(); // Will destroy |this|.
|
| + }
|
| +
|
| + // Called from the owning class to change the menu content to the given
|
| + // |snap_type| so that the user knows what is selected.
|
| + void SetMenuState(FrameMaximizeButton::SnapType snap_type) {
|
| + if (contents_view_)
|
| + contents_view_->SetMenuState(snap_type);
|
| + }
|
| +
|
| + private:
|
| + // Our owning class.
|
| + MaximizeBubble* bubble_;
|
| +
|
| + // The widget which contains our menu and the bubble border.
|
| + views::Widget* bubble_widget_;
|
| +
|
| + // The content accessor of the menu.
|
| + BubbleContentsView* contents_view_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Bubble);
|
| +};
|
| +
|
| +MaximizeBubble::MaximizeBubble(FrameMaximizeButton* frame_maximize_button,
|
| + bool is_maximized)
|
| + : frame_maximize_button_(frame_maximize_button),
|
| + bubble_(NULL),
|
| + radial_menu_(NULL),
|
| + current_radial_snap_hover_type_(FrameMaximizeButton::SNAP_NONE),
|
| + is_maximized_(is_maximized) {
|
| + // Create the task which will create the bubble delayed.
|
| + base::OneShotTimer<MaximizeBubble>* new_timer =
|
| + new base::OneShotTimer<MaximizeBubble>();
|
| + new_timer->Start(
|
| + FROM_HERE,
|
| + base::TimeDelta::FromMilliseconds(kBubbleAppearanceDelay),
|
| + this,
|
| + &MaximizeBubble::DelayedBubbleCreation);
|
| + timer_.reset(new_timer);
|
| +}
|
| +
|
| +void MaximizeBubble::DelayCreation() {
|
| + if (timer_.get() && timer_->IsRunning())
|
| + timer_->Reset();
|
| +}
|
| +
|
| +void MaximizeBubble::DelayedBubbleCreation() {
|
| + if (!bubble_ && !radial_menu_) {
|
| + if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableTouchRadialMenu)) {
|
| + std::vector<views::RadialMenuItem*> items;
|
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
|
| + DCHECK(RADIAL_MENU_NONE == items.size());
|
| + items.push_back(views::RadialMenuItem::CreateRadialMenuItemInstance(
|
| + views::RadialMenuItem::RADIAL_SEPARATOR,
|
| + NULL,
|
| + false));
|
| + DCHECK(RADIAL_MENU_RIGHT == items.size());
|
| + items.push_back(views::RadialMenuItem::CreateRadialMenuItemInstance(
|
| + views::RadialMenuItem::RADIAL_BUTTON,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_RIGHT_P),
|
| + false));
|
| + DCHECK(RADIAL_MENU_MINIMIZE == items.size());
|
| + items.push_back(views::RadialMenuItem::CreateRadialMenuItemInstance(
|
| + views::RadialMenuItem::RADIAL_BUTTON,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_P),
|
| + false));
|
| + DCHECK(RADIAL_MENU_LEFT == items.size());
|
| + items.push_back(views::RadialMenuItem::CreateRadialMenuItemInstance(
|
| + views::RadialMenuItem::RADIAL_BUTTON,
|
| + // TODO(skuhne): Replace images as soon as they come in.
|
| + rb.GetImageSkiaNamed(IDR_AURA_WINDOW_SNAP_LEFT_P),
|
| + false));
|
| + gfx::Rect rect = frame_maximize_button()->GetBoundsInScreen();
|
| + gfx::Point location = rect.CenterPoint();
|
| + int radius = (rect.width() < rect.height() ? rect.width() :
|
| + rect.height()) / 2;
|
| + // Shrinking the radius slightly to avoid having the radial menu not
|
| + // covering the entire button.
|
| + radius -= radius / 10;
|
| + radial_menu_ = views::RadialMenu::CreateRadialMenuInstance(
|
| + location, // Location center is always the center of the button.
|
| + 3 * radius, // The outer radius hits the end of the window.
|
| + radius, // The button itself is minimally covered.
|
| + 0.0,
|
| + items,
|
| + kHoverRadialMenuExtension,
|
| + false); // Do not crop the menu to the screen.
|
| + // A global event handler gets added to keep track of radial menu related
|
| + // mouse move updates. This filter only tracks mouse movement when no key
|
| + // is pressed.
|
| + ash::Shell::GetInstance()->AddEnvEventFilter(this);
|
| + } else {
|
| + bubble_ = new Bubble(this);
|
| + }
|
| + }
|
| + timer_.reset(NULL);
|
| +}
|
| +
|
| +MaximizeBubble::~MaximizeBubble() {
|
| + timer_.reset(NULL);
|
| + if (bubble_) {
|
| + // To avoid recursive destruction we make sure to clear the destroyed
|
| + // objects pointer before we tell it to destroy itself.
|
| + Bubble* bubble = bubble_;
|
| + bubble_ = NULL;
|
| + bubble->Close();
|
| + }
|
| + if (radial_menu_) {
|
| + // To avoid recursive destruction we make sure to clear the destroyed
|
| + // objects pointer before we tell it to destroy itself.
|
| + ash::Shell::GetInstance()->RemoveEnvEventFilter(this);
|
| + views::RadialMenu* radial_menu = radial_menu_;
|
| + radial_menu_ = NULL;
|
| + radial_menu->CloseAndDelete(false);
|
| + }
|
| +}
|
| +
|
| +void MaximizeBubble::Close() {
|
| + timer_.reset(NULL);
|
| + // Note: If |bubble_| is NULL, we are in process of deleting the menu.
|
| + if (bubble_ || radial_menu_)
|
| + frame_maximize_button_->DestroyMaximizeMenu();
|
| +}
|
| +
|
| +void MaximizeBubble::OnButtonClicked(FrameMaximizeButton::SnapType snap_type) {
|
| + frame_maximize_button_->SnapButtonClicked(snap_type);
|
| + // Once it was clicked we can close the menu.
|
| + Close();
|
| +}
|
| +
|
| +void MaximizeBubble::OnButtonHover(FrameMaximizeButton::SnapType snap_type) {
|
| + frame_maximize_button_->SnapButtonHovered(snap_type);
|
| +}
|
| +
|
| +void MaximizeBubble::SetMenuState(FrameMaximizeButton::SnapType snap_type) {
|
| + if (bubble_)
|
| + bubble_->SetMenuState(snap_type);
|
| +}
|
| +
|
| +aura::Window* MaximizeBubble::GetMenuWindow() {
|
| + return bubble_ ? bubble_->GetMenuWindow() :
|
| + (radial_menu_ ? radial_menu_->GetWindow() : NULL);
|
| +}
|
| +
|
| +// Functions added for the experimental radial menu.
|
| +
|
| +bool MaximizeBubble::IsRadialMenu() {
|
| + return radial_menu_ ? true : false;
|
| +}
|
| +
|
| +bool MaximizeBubble::SnapTypeForLocation(
|
| + const gfx::Point& location,
|
| + FrameMaximizeButton::SnapType& type) {
|
| + int item = -1;
|
| + if (radial_menu_) {
|
| + int count = 0;
|
| + // Depending on the hover / drag operation we use different
|
| + // 'activateable areas' behind a segment: In case of hover we cancel the
|
| + // menu when we get a bit away - for drag operations however we do not
|
| + // cancel the operation at all (at least not from within the menu).
|
| + int max_activatable_area = frame_maximize_button_->is_snap_enabled() ?
|
| + kDragRadialMenuExtension : kHoverRadialMenuExtension;
|
| + radial_menu_->set_pointer_activation_area_extension(max_activatable_area);
|
| + radial_menu_->HitMenuItemTest(location, &item, &count);
|
| + }
|
| + switch (item) {
|
| + case RADIAL_MENU_RIGHT:
|
| + type = FrameMaximizeButton::SNAP_RIGHT;
|
| + return true;
|
| + case RADIAL_MENU_MINIMIZE:
|
| + type = FrameMaximizeButton::SNAP_MINIMIZE;
|
| + return true;
|
| + case RADIAL_MENU_LEFT:
|
| + type = FrameMaximizeButton::SNAP_LEFT;
|
| + return true;
|
| + default:
|
| + type = FrameMaximizeButton::SNAP_NONE;
|
| + return false;
|
| + }
|
| +}
|
| +
|
| +bool MaximizeBubble::PreHandleKeyEvent(aura::Window* target,
|
| + aura::KeyEvent* event) {
|
| + return false;
|
| +}
|
| +
|
| +bool MaximizeBubble::PreHandleMouseEvent(aura::Window* target,
|
| + aura::MouseEvent* event) {
|
| + if (event->type() == ui::ET_MOUSE_MOVED &&
|
| + !frame_maximize_button_->is_snap_enabled()) {
|
| + // If we are neither over our menu, nor over the button itself we close
|
| + // the menu.
|
| + gfx::Point pt = gfx::Screen::GetCursorScreenPoint();
|
| + if (!SnapTypeForLocation(pt, current_radial_snap_hover_type_) &&
|
| + !frame_maximize_button()->GetBoundsInScreen().Contains(pt)) {
|
| + OnButtonHover(FrameMaximizeButton::SNAP_NONE);
|
| + Close();
|
| + } else
|
| + OnButtonHover(current_radial_snap_hover_type_);
|
| + }
|
| +
|
| + if (event->type() == ui::ET_MOUSE_PRESSED &&
|
| + !frame_maximize_button_->is_snap_enabled() &&
|
| + current_radial_snap_hover_type_ != FrameMaximizeButton::SNAP_NONE) {
|
| + OnButtonClicked(current_radial_snap_hover_type_);
|
| + // This action was consumed here.
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +ui::TouchStatus MaximizeBubble::PreHandleTouchEvent(
|
| + aura::Window* target,
|
| + aura::TouchEvent* event) {
|
| + return ui::TOUCH_STATUS_UNKNOWN;
|
| +}
|
| +
|
| +ui::GestureStatus MaximizeBubble::PreHandleGestureEvent(
|
| + aura::Window* target, aura::GestureEvent* event) {
|
| + return ui::GESTURE_STATUS_UNKNOWN;
|
| +}
|
| +
|
| +} // namespace ash
|
|
|