Mac: Fix performance issues with remote CoreAnimation
[chromium-blink-merge.git] / ash / wm / overview / transparent_activate_window_button.cc
blob9056e7ae3ff85b609e43c20d53e5fad5a423f087
1 // Copyright 2014 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.
5 #include "ash/wm/overview/transparent_activate_window_button.h"
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_state.h"
10 #include "ui/views/controls/button/custom_button.h"
11 #include "ui/views/widget/widget.h"
13 namespace ash {
15 namespace {
16 const char kTransparentButtonName[] = "TransparentButton";
18 // Transparent button that handles events which activate windows in overview
19 // mode.
20 class TransparentButton : public views::CustomButton {
21 public:
22 explicit TransparentButton(views::ButtonListener* listener)
23 : CustomButton(listener) {
25 ~TransparentButton() override {}
27 // views::CustomButton:
28 void OnGestureEvent(ui::GestureEvent* event) override {
29 // TODO(tdanderson): Re-evaluate whether we want to set capture once
30 // the a fix has landed to avoid crashing when a window
31 // having an active gesture sequence is destroyed as a
32 // result of a gesture in a separate window.
33 if (event->type() == ui::ET_GESTURE_TAP_DOWN)
34 GetWidget()->SetCapture(this);
36 if (event->type() == ui::ET_GESTURE_TAP ||
37 event->type() == ui::ET_GESTURE_END) {
38 GetWidget()->ReleaseCapture();
41 CustomButton::OnGestureEvent(event);
42 event->StopPropagation();
45 const char* GetClassName() const override { return kTransparentButtonName; }
47 private:
48 DISALLOW_COPY_AND_ASSIGN(TransparentButton);
51 // Initializes the event handler transparent window.
52 views::Widget* InitEventHandler(aura::Window* root_window) {
53 views::Widget* widget = new views::Widget;
54 views::Widget::InitParams params;
55 params.type = views::Widget::InitParams::TYPE_POPUP;
56 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
57 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
58 params.accept_events = true;
59 params.parent = Shell::GetContainer(root_window,
60 kShellWindowId_OverlayContainer);
61 widget->set_focus_on_creation(false);
62 widget->Init(params);
63 widget->Show();
65 aura::Window* handler = widget->GetNativeWindow();
66 handler->parent()->StackChildAtBottom(handler);
68 return widget;
71 } // namespace
73 TransparentActivateWindowButton::TransparentActivateWindowButton(
74 aura::Window* activate_window)
75 : event_handler_widget_(InitEventHandler(activate_window->GetRootWindow())),
76 activate_window_(activate_window) {
77 views::Button* transparent_button = new TransparentButton(this);
78 transparent_button->SetAccessibleName(activate_window->title());
79 event_handler_widget_->SetContentsView(transparent_button);
82 void TransparentActivateWindowButton::SetBounds(const gfx::Rect& bounds) {
83 event_handler_widget_->SetBounds(bounds);
86 void TransparentActivateWindowButton::SendFocusAlert() const {
87 event_handler_widget_->GetContentsView()->
88 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, true);
91 TransparentActivateWindowButton::~TransparentActivateWindowButton() {
94 void TransparentActivateWindowButton::ButtonPressed(views::Button* sender,
95 const ui::Event& event) {
96 wm::GetWindowState(activate_window_)->Activate();
99 } // namespace ash