OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/screen_util.h" |
| 6 #include "ash/shell.h" |
| 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/wm/overview/overview_animation_type.h" |
| 9 #include "ash/wm/overview/overview_window_button.h" |
| 10 #include "ash/wm/overview/overview_window_targeter.h" |
| 11 #include "ash/wm/overview/scoped_overview_animation_settings.h" |
| 12 #include "ash/wm/window_state.h" |
| 13 #include "ui/aura/scoped_window_targeter.h" |
| 14 #include "ui/aura/window.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/button/label_button.h" |
| 18 #include "ui/views/widget/widget.h" |
| 19 |
| 20 namespace ash { |
| 21 |
| 22 namespace { |
| 23 |
| 24 // Foreground label color. |
| 25 static const SkColor kLabelColor = SK_ColorWHITE; |
| 26 |
| 27 // Label shadow color. |
| 28 static const SkColor kLabelShadow = 0xB0000000; |
| 29 |
| 30 // Solid shadow length from the label |
| 31 static const int kVerticalShadowOffset = 1; |
| 32 |
| 33 // Amount of blur applied to the label shadow |
| 34 static const int kShadowBlur = 10; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 // LabelButton shown under each of the windows. |
| 39 class OverviewWindowButton::OverviewButtonView : public views::LabelButton { |
| 40 public: |
| 41 OverviewButtonView(views::ButtonListener* listener, |
| 42 const base::string16& text) |
| 43 : views::LabelButton(listener, text), |
| 44 selector_item_bounds_(gfx::Rect()) {} |
| 45 |
| 46 ~OverviewButtonView() override {} |
| 47 |
| 48 // Updates the |selector_item_bounds_|, converting them to our coordinates. |
| 49 void SetSelectorItemBounds(const gfx::Rect& selector_item_bounds) { |
| 50 selector_item_bounds_ = ScreenUtil::ConvertRectFromScreen( |
| 51 GetWidget()->GetNativeWindow()->GetRootWindow(), selector_item_bounds); |
| 52 gfx::Point origin = selector_item_bounds_.origin(); |
| 53 gfx::Rect target_bounds = GetWidget()->GetNativeWindow()->GetTargetBounds(); |
| 54 origin.Offset(-target_bounds.x(), -target_bounds.y()); |
| 55 selector_item_bounds_.set_origin(origin); |
| 56 } |
| 57 |
| 58 // views::View: |
| 59 void OnMouseReleased(const ui::MouseEvent& event) override { |
| 60 if (!selector_item_bounds_.Contains(event.location())) |
| 61 return; |
| 62 |
| 63 NotifyClick(event); |
| 64 } |
| 65 |
| 66 private: |
| 67 // Bounds to check if a mouse release occurred outside the window item. |
| 68 gfx::Rect selector_item_bounds_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(OverviewButtonView); |
| 71 }; |
| 72 |
| 73 OverviewWindowButton::OverviewWindowButton(aura::Window* target) |
| 74 : target_(target), window_label_(new views::Widget) { |
| 75 views::Widget::InitParams params; |
| 76 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 77 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 78 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 79 params.parent = Shell::GetContainer(target_->GetRootWindow(), |
| 80 kShellWindowId_OverlayContainer); |
| 81 params.visible_on_all_workspaces = true; |
| 82 window_label_->set_focus_on_creation(false); |
| 83 window_label_->Init(params); |
| 84 window_label_button_view_ = new OverviewButtonView(this, target_->title()); |
| 85 window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL, |
| 86 kLabelColor); |
| 87 window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED, |
| 88 kLabelColor); |
| 89 window_label_button_view_->SetTextColor(views::LabelButton::STATE_PRESSED, |
| 90 kLabelColor); |
| 91 window_label_button_view_->set_animate_on_state_change(false); |
| 92 window_label_button_view_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 93 window_label_button_view_->SetBorder(views::Border::NullBorder()); |
| 94 window_label_button_view_->SetTextShadows(gfx::ShadowValues( |
| 95 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur, |
| 96 kLabelShadow))); |
| 97 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 98 window_label_button_view_->SetFontList( |
| 99 bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
| 100 window_label_->SetContentsView(window_label_button_view_); |
| 101 |
| 102 overview_window_targeter_ = |
| 103 new OverviewWindowTargeter(window_label_->GetNativeWindow()); |
| 104 scoped_window_targeter_.reset(new aura::ScopedWindowTargeter( |
| 105 target, scoped_ptr<OverviewWindowTargeter>(overview_window_targeter_))); |
| 106 } |
| 107 |
| 108 OverviewWindowButton::~OverviewWindowButton() { |
| 109 } |
| 110 |
| 111 void OverviewWindowButton::SetBounds( |
| 112 const gfx::Rect& bounds, |
| 113 const OverviewAnimationType& animation_type) { |
| 114 if (!window_label_->IsVisible()) { |
| 115 window_label_->Show(); |
| 116 ScopedOverviewAnimationSettings::SetupFadeInAfterLayout( |
| 117 window_label_->GetNativeWindow()); |
| 118 } |
| 119 gfx::Rect converted_bounds = |
| 120 ScreenUtil::ConvertRectFromScreen(target_->GetRootWindow(), bounds); |
| 121 gfx::Rect label_bounds(converted_bounds.x(), converted_bounds.bottom(), |
| 122 converted_bounds.width(), 0); |
| 123 label_bounds.set_height( |
| 124 window_label_->GetContentsView()->GetPreferredSize().height()); |
| 125 label_bounds.set_y( |
| 126 label_bounds.y() - |
| 127 window_label_->GetContentsView()->GetPreferredSize().height()); |
| 128 |
| 129 ScopedOverviewAnimationSettings animation_settings( |
| 130 animation_type, window_label_->GetNativeWindow()); |
| 131 |
| 132 window_label_->GetNativeWindow()->SetBounds(label_bounds); |
| 133 window_label_button_view_->SetSelectorItemBounds(bounds); |
| 134 overview_window_targeter_->set_bounds( |
| 135 ScreenUtil::ConvertRectFromScreen(target_->GetRootWindow(), bounds)); |
| 136 } |
| 137 |
| 138 void OverviewWindowButton::SendFocusAlert() const { |
| 139 window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
| 140 } |
| 141 |
| 142 void OverviewWindowButton::SetLabelText(const base::string16& title) { |
| 143 window_label_button_view_->SetText(title); |
| 144 } |
| 145 |
| 146 void OverviewWindowButton::SetOpacity(float opacity) { |
| 147 window_label_->GetNativeWindow()->layer()->SetOpacity(opacity); |
| 148 } |
| 149 |
| 150 void OverviewWindowButton::ButtonPressed(views::Button* sender, |
| 151 const ui::Event& event) { |
| 152 wm::GetWindowState(target_)->Activate(); |
| 153 } |
| 154 |
| 155 } // namespace ash |
OLD | NEW |