Chromium Code Reviews| Index: ash/wm/overview/window_selector_item.cc |
| diff --git a/ash/wm/overview/window_selector_item.cc b/ash/wm/overview/window_selector_item.cc |
| index 4ab47e98f886f30233175bac716550e33e2c5b95..7451dcf0cc9cbe372ebf60c51e05eab59c9d4942 100644 |
| --- a/ash/wm/overview/window_selector_item.cc |
| +++ b/ash/wm/overview/window_selector_item.cc |
| @@ -11,6 +11,7 @@ |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| #include "ash/wm/overview/overview_animation_type.h" |
| +#include "ash/wm/overview/overview_window_targeter.h" |
| #include "ash/wm/overview/scoped_overview_animation_settings.h" |
| #include "ash/wm/overview/scoped_transform_overview_window.h" |
| #include "ash/wm/overview/window_selector_controller.h" |
| @@ -27,8 +28,8 @@ |
| #include "ui/gfx/geometry/vector2d.h" |
| #include "ui/gfx/transform_util.h" |
| #include "ui/strings/grit/ui_strings.h" |
| +#include "ui/views/border.h" |
| #include "ui/views/controls/button/image_button.h" |
| -#include "ui/views/controls/label.h" |
| #include "ui/views/layout/box_layout.h" |
| #include "ui/views/widget/widget.h" |
| #include "ui/wm/core/window_util.h" |
| @@ -45,15 +46,9 @@ static const int kWindowMargin = 30; |
| // Foreground label color. |
| static const SkColor kLabelColor = SK_ColorWHITE; |
| -// Background label color. |
| -static const SkColor kLabelBackground = SK_ColorTRANSPARENT; |
| - |
| // Label shadow color. |
| static const SkColor kLabelShadow = 0xB0000000; |
| -// Vertical padding for the label, both over and beneath it. |
| -static const int kVerticalLabelPadding = 20; |
| - |
| // Solid shadow length from the label |
| static const int kVerticalShadowOffset = 1; |
| @@ -113,15 +108,51 @@ OverviewCloseButton::~OverviewCloseButton() { |
| } // namespace |
| +// LabelButton shown under each of the windows. |
| +// The button is activated as soon as the mouse is pressed to avoid relying on |
| +// the mouse up to target this view. |
|
tdanderson
2015/01/22 20:43:58
Since you're activating on mouse release (the curr
Nina
2015/01/22 22:25:39
Done.
|
| +class WindowSelectorItem::OverviewLabelButton : public views::LabelButton { |
| + public: |
| + OverviewLabelButton(views::ButtonListener* listener, |
| + const base::string16& text) |
| + : views::LabelButton(listener, text), event_bounds_(gfx::Rect()) {} |
| + |
| + ~OverviewLabelButton() override {} |
| + |
| + // Updates the |event_bounds|, converting them to our coordinates. |
|
tdanderson
2015/01/22 20:43:58
|event_bounds_|.
Nina
2015/01/22 22:25:39
Done.
|
| + void SetEventBounds(const gfx::Rect& event_bounds) { |
| + event_bounds_ = ScreenUtil::ConvertRectFromScreen( |
| + GetWidget()->GetNativeWindow()->GetRootWindow(), event_bounds); |
| + gfx::Point origin = event_bounds_.origin(); |
| + gfx::Rect target_bounds = GetWidget()->GetNativeWindow()->GetTargetBounds(); |
| + origin.Offset(-target_bounds.x(), -target_bounds.y()); |
| + event_bounds_.set_origin(origin); |
| + } |
| + |
| + // views::View: |
| + void OnMouseReleased(const ui::MouseEvent& event) override { |
| + if (!event_bounds_.Contains(event.location())) |
| + return; |
| + |
| + NotifyClick(event); |
| + } |
| + |
| + private: |
| + // Bounds to check if a mouse release occurred outside the window item. |
| + gfx::Rect event_bounds_; |
|
tdanderson
2015/01/22 20:43:58
It's not immediately clear what "event bounds" mea
Nina
2015/01/22 22:25:39
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(OverviewLabelButton); |
| +}; |
| + |
| WindowSelectorItem::WindowSelectorItem(aura::Window* window) |
| : dimmed_(false), |
| root_window_(window->GetRootWindow()), |
| transform_window_(window), |
| in_bounds_update_(false), |
| - window_label_view_(nullptr), |
| + window_label_button_view_(nullptr), |
| close_button_(new OverviewCloseButton(this)), |
| - selector_item_activate_window_button_( |
| - new TransparentActivateWindowButton(root_window_, this)) { |
| + overview_window_targeter_(nullptr), |
| + scoped_window_targeter_(nullptr) { |
| views::Widget::InitParams params; |
| params.type = views::Widget::InitParams::TYPE_POPUP; |
| params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| @@ -144,8 +175,14 @@ WindowSelectorItem::WindowSelectorItem(aura::Window* window) |
| close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect); |
| GetWindow()->AddObserver(this); |
| + CreateWindowLabel(); |
| UpdateCloseButtonAccessibilityName(); |
| + |
| + overview_window_targeter_ = |
| + new OverviewWindowTargeter(window_label_->GetNativeWindow()); |
| + scoped_window_targeter_.reset(new aura::ScopedWindowTargeter( |
| + window, scoped_ptr<OverviewWindowTargeter>(overview_window_targeter_))); |
| } |
| WindowSelectorItem::~WindowSelectorItem() { |
| @@ -188,7 +225,6 @@ void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, |
| // SetItemBounds is called before UpdateCloseButtonLayout so the close button |
| // can properly use the updated windows bounds. |
| UpdateCloseButtonLayout(animation_type); |
| - UpdateSelectorButtons(); |
| } |
| void WindowSelectorItem::RecomputeWindowTransforms() { |
| @@ -198,13 +234,11 @@ void WindowSelectorItem::RecomputeWindowTransforms() { |
| gfx::Rect inset_bounds(target_bounds_); |
| inset_bounds.Inset(kWindowMargin, kWindowMargin); |
| SetItemBounds(inset_bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
| - |
| UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
| - UpdateSelectorButtons(); |
| } |
| void WindowSelectorItem::SendFocusAlert() const { |
| - selector_item_activate_window_button_->SendFocusAlert(); |
| + window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| } |
| void WindowSelectorItem::SetDimmed(bool dimmed) { |
| @@ -214,7 +248,12 @@ void WindowSelectorItem::SetDimmed(bool dimmed) { |
| void WindowSelectorItem::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| - transform_window_.Close(); |
| + if (sender == close_button_) { |
| + transform_window_.Close(); |
| + return; |
| + } |
| + DCHECK(sender == window_label_button_view_); |
| + wm::GetWindowState(GetWindow())->Activate(); |
| } |
| void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { |
| @@ -225,18 +264,8 @@ void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { |
| void WindowSelectorItem::OnWindowTitleChanged(aura::Window* window) { |
| // TODO(flackr): Maybe add the new title to a vector of titles so that we can |
| // filter any of the titles the window had while in the overview session. |
| - if (window == GetWindow()) { |
| - window_label_view_->SetText(window->title()); |
| - UpdateCloseButtonAccessibilityName(); |
| - } |
| - UpdateCloseButtonLayout(OverviewAnimationType::OVERVIEW_ANIMATION_NONE); |
| - UpdateSelectorButtons(); |
| -} |
| - |
| -void WindowSelectorItem::Select() { |
| - aura::Window* selection_window = GetWindow(); |
| - if (selection_window) |
| - wm::GetWindowState(selection_window)->Activate(); |
| + window_label_button_view_->SetText(window->title()); |
| + UpdateCloseButtonAccessibilityName(); |
| } |
| void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
| @@ -253,6 +282,8 @@ void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
| transform_window_.BeginScopedAnimation(animation_type, &animation_settings); |
| transform_window_.SetTransform(root_window_, transform); |
| transform_window_.set_overview_transform(transform); |
| + overview_window_targeter_->set_bounds( |
| + ScreenUtil::ConvertRectFromScreen(root_window_, target_bounds)); |
| } |
| void WindowSelectorItem::SetOpacity(float opacity) { |
| @@ -265,12 +296,10 @@ void WindowSelectorItem::SetOpacity(float opacity) { |
| void WindowSelectorItem::UpdateWindowLabels( |
| const gfx::Rect& window_bounds, |
| OverviewAnimationType animation_type) { |
| - |
| - if (!window_label_) { |
| - CreateWindowLabel(GetWindow()->title()); |
| + if (!window_label_->IsVisible()) { |
| + window_label_->Show(); |
| SetupFadeInAfterLayout(window_label_->GetNativeWindow()); |
| } |
| - |
| gfx::Rect converted_bounds = ScreenUtil::ConvertRectFromScreen(root_window_, |
| window_bounds); |
| gfx::Rect label_bounds(converted_bounds.x(), |
| @@ -286,9 +315,10 @@ void WindowSelectorItem::UpdateWindowLabels( |
| window_label_->GetNativeWindow()); |
| window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| + window_label_button_view_->SetEventBounds(target_bounds_); |
| } |
| -void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
| +void WindowSelectorItem::CreateWindowLabel() { |
| window_label_.reset(new views::Widget); |
| views::Widget::InitParams params; |
| params.type = views::Widget::InitParams::TYPE_POPUP; |
| @@ -296,40 +326,27 @@ void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
| params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| params.parent = Shell::GetContainer(root_window_, |
| kShellWindowId_OverlayContainer); |
| - params.accept_events = false; |
| params.visible_on_all_workspaces = true; |
| window_label_->set_focus_on_creation(false); |
| window_label_->Init(params); |
| - window_label_view_ = new views::Label; |
| - window_label_view_->SetEnabledColor(kLabelColor); |
| - window_label_view_->SetBackgroundColor(kLabelBackground); |
| - window_label_view_->SetShadows(gfx::ShadowValues( |
| - 1, |
| - gfx::ShadowValue( |
| - gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow))); |
| + window_label_button_view_ = |
| + new OverviewLabelButton(this, GetWindow()->title()); |
| + window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL, |
| + kLabelColor); |
| + window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED, |
| + kLabelColor); |
| + window_label_button_view_->SetTextColor(views::LabelButton::STATE_PRESSED, |
| + kLabelColor); |
| + window_label_button_view_->set_animate_on_state_change(false); |
| + window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| + window_label_button_view_->SetBorder(views::Border::NullBorder()); |
| + window_label_button_view_->SetTextShadows(gfx::ShadowValues( |
| + 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur, |
| + kLabelShadow))); |
| ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| - window_label_view_->SetFontList( |
| + window_label_button_view_->SetFontList( |
| bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
| - window_label_view_->SetText(title); |
| - views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, |
| - 0, |
| - kVerticalLabelPadding, |
| - 0); |
| - window_label_view_->SetLayoutManager(layout); |
| - window_label_->SetContentsView(window_label_view_); |
| - window_label_->Show(); |
| -} |
| - |
| -void WindowSelectorItem::UpdateSelectorButtons() { |
| - aura::Window* window = GetWindow(); |
| - |
| - selector_item_activate_window_button_->SetBounds(target_bounds()); |
| - selector_item_activate_window_button_->SetAccessibleName(window->title()); |
| - |
| - TransparentActivateWindowButton* activate_button = |
| - transform_window_.activate_button(); |
| - activate_button->SetBounds(target_bounds()); |
| - activate_button->SetAccessibleName(window->title()); |
| + window_label_->SetContentsView(window_label_button_view_); |
| } |
| void WindowSelectorItem::UpdateCloseButtonLayout( |