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 d57f0adbafafbfc810ff8cbfd0209f35a8b0df4e..becda9aae5ea557c0c1a82c7fc5c645c13964f52 100644 |
--- a/ash/wm/overview/window_selector_item.cc |
+++ b/ash/wm/overview/window_selector_item.cc |
@@ -11,10 +11,10 @@ |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
#include "ash/wm/overview/overview_animation_type.h" |
-#include "ash/wm/overview/overview_window_button.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" |
+#include "ash/wm/window_state.h" |
#include "base/auto_reset.h" |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
@@ -27,7 +27,9 @@ |
#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/button/label_button.h" |
#include "ui/views/layout/box_layout.h" |
#include "ui/views/widget/widget.h" |
#include "ui/wm/core/window_util.h" |
@@ -41,9 +43,40 @@ namespace { |
// closest distance between adjacent windows will be twice this amount. |
static const int kWindowMargin = 30; |
+// Foreground label color. |
+static const SkColor kLabelColor = SK_ColorWHITE; |
+ |
+// Label shadow color. |
+static const SkColor kLabelShadow = 0xB0000000; |
+ |
+// Vertical padding for the label, on top of it. |
+static const int kVerticalLabelPadding = 20; |
+ |
+// Solid shadow length from the label |
+static const int kVerticalShadowOffset = 1; |
+ |
+// Amount of blur applied to the label shadow |
+static const int kShadowBlur = 10; |
+ |
// Opacity for dimmed items. |
static const float kDimmedItemOpacity = 0.5f; |
+class OverviewLabelButton : public views::LabelButton { |
+ public: |
+ OverviewLabelButton(views::ButtonListener* listener, |
+ const base::string16& text) |
+ : LabelButton(listener, text) {} |
+ |
+ ~OverviewLabelButton() override {} |
+ |
+ protected: |
+ gfx::Rect GetChildAreaBounds() override { |
+ gfx::Rect bounds = GetLocalBounds(); |
+ bounds.Inset(GetInsets()); |
msw
2015/02/06 21:24:26
This will double-apply border insets, instead, her
Nina
2015/02/09 16:35:09
Done.
msw
2015/02/09 23:45:27
Acknowledged.
|
+ return bounds; |
+ } |
+}; |
+ |
// Calculates the |window| bounds after being transformed to the selector's |
// space. The returned Rect is in virtual screen coordinates. |
gfx::Rect GetTransformedBounds(aura::Window* window) { |
@@ -87,8 +120,9 @@ WindowSelectorItem::WindowSelectorItem(aura::Window* window) |
root_window_(window->GetRootWindow()), |
transform_window_(window), |
in_bounds_update_(false), |
- close_button_(new OverviewCloseButton(this)), |
- overview_window_button_(new OverviewWindowButton(window)) { |
+ window_label_button_view_(nullptr), |
+ close_button_(new OverviewCloseButton(this)) { |
+ CreateWindowLabel(window->title()); |
views::Widget::InitParams params; |
params.type = views::Widget::InitParams::TYPE_POPUP; |
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
@@ -111,8 +145,6 @@ WindowSelectorItem::WindowSelectorItem(aura::Window* window) |
close_button_widget_.GetNativeWindow()->SetBounds(close_button_rect); |
GetWindow()->AddObserver(this); |
- |
- UpdateCloseButtonAccessibilityName(); |
} |
WindowSelectorItem::~WindowSelectorItem() { |
@@ -146,8 +178,6 @@ void WindowSelectorItem::SetBounds(const gfx::Rect& target_bounds, |
base::AutoReset<bool> auto_reset_in_bounds_update(&in_bounds_update_, true); |
target_bounds_ = target_bounds; |
- overview_window_button_->SetBounds(target_bounds, animation_type); |
- |
gfx::Rect inset_bounds(target_bounds); |
inset_bounds.Inset(kWindowMargin, kWindowMargin); |
SetItemBounds(inset_bounds, animation_type); |
@@ -155,6 +185,7 @@ 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); |
+ UpdateWindowLabel(target_bounds, animation_type); |
} |
void WindowSelectorItem::RecomputeWindowTransforms() { |
@@ -168,7 +199,7 @@ void WindowSelectorItem::RecomputeWindowTransforms() { |
} |
void WindowSelectorItem::SendFocusAlert() const { |
- overview_window_button_->SendFocusAlert(); |
+ window_label_button_view_->NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true); |
} |
void WindowSelectorItem::SetDimmed(bool dimmed) { |
@@ -178,7 +209,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; |
+ } |
+ CHECK(sender == window_label_button_view_); |
+ wm::GetWindowState(transform_window_.window())->Activate(); |
} |
void WindowSelectorItem::OnWindowDestroying(aura::Window* window) { |
@@ -189,7 +225,7 @@ 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. |
- overview_window_button_->SetLabelText(window->title()); |
+ window_label_button_view_->SetText(window->title()); |
UpdateCloseButtonAccessibilityName(); |
} |
@@ -210,12 +246,67 @@ void WindowSelectorItem::SetItemBounds(const gfx::Rect& target_bounds, |
} |
void WindowSelectorItem::SetOpacity(float opacity) { |
- overview_window_button_->SetOpacity(opacity); |
+ window_label_->GetNativeWindow()->layer()->SetOpacity(opacity); |
close_button_widget_.GetNativeWindow()->layer()->SetOpacity(opacity); |
transform_window_.SetOpacity(opacity); |
} |
+void WindowSelectorItem::UpdateWindowLabel( |
+ const gfx::Rect& window_bounds, |
+ OverviewAnimationType animation_type) { |
+ // If the root window has changed, force the window label to be recreated |
+ // and faded in on the new root window. |
+ DCHECK(!window_label_ || |
+ window_label_->GetNativeWindow()->GetRootWindow() == root_window_); |
+ |
+ if (!window_label_->IsVisible()) { |
+ window_label_->Show(); |
+ ScopedOverviewAnimationSettings::SetupFadeInAfterLayout( |
+ window_label_->GetNativeWindow()); |
+ } |
+ |
+ gfx::Rect converted_bounds = |
+ ScreenUtil::ConvertRectFromScreen(root_window_, window_bounds); |
+ gfx::Rect label_bounds(converted_bounds.x(), converted_bounds.y(), |
+ converted_bounds.width(), converted_bounds.height()); |
+ window_label_button_view_->SetBorder(views::Border::CreateEmptyBorder( |
+ label_bounds.height() - kVerticalLabelPadding, 0, 0, 0)); |
+ ScopedOverviewAnimationSettings animation_settings( |
+ animation_type, window_label_->GetNativeWindow()); |
+ |
+ window_label_->GetNativeWindow()->SetBounds(label_bounds); |
+} |
+ |
+void WindowSelectorItem::CreateWindowLabel(const base::string16& title) { |
+ window_label_.reset(new views::Widget); |
+ views::Widget::InitParams params; |
+ params.type = views::Widget::InitParams::TYPE_POPUP; |
+ params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
+ params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
+ params.parent = |
+ Shell::GetContainer(root_window_, kShellWindowId_OverlayContainer); |
+ params.visible_on_all_workspaces = true; |
+ window_label_->set_focus_on_creation(false); |
+ window_label_->Init(params); |
+ window_label_button_view_ = new OverviewLabelButton(this, title); |
+ window_label_button_view_->SetTextColor(views::LabelButton::STATE_NORMAL, |
+ kLabelColor); |
+ window_label_button_view_->SetTextColor(views::LabelButton::STATE_HOVERED, |
msw
2015/02/06 21:24:26
I don't think you need to explicitly set the text
Nina
2015/02/09 16:35:09
It seems they don't - removing the lines makes the
msw
2015/02/09 23:45:27
Acknowledged. Sorry, it probably should behave as
|
+ 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_->SetTextShadows(gfx::ShadowValues( |
+ 1, gfx::ShadowValue(gfx::Point(0, kVerticalShadowOffset), kShadowBlur, |
+ kLabelShadow))); |
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
+ window_label_button_view_->SetFontList( |
+ bundle.GetFontList(ui::ResourceBundle::BoldFont)); |
+ window_label_->SetContentsView(window_label_button_view_); |
+} |
+ |
void WindowSelectorItem::UpdateCloseButtonLayout( |
OverviewAnimationType animation_type) { |
if (!close_button_->visible()) { |