Commit 6ede2cb2 authored by David Black's avatar David Black Committed by Commit Bot

Use ClientView instead of DialogClientView for Assistant.

Previously we used a DialogClientView which supported handling of the
ESCAPE key to close the widget. Now, we're switching to the lighter
weight ClientView which necessitates us adding ESCAPE support ourselves.

Bug: b:123607402
Change-Id: I64c1fe1cd38f6f9daafc993956c10f143fa5a4f4
Reviewed-on: https://chromium-review.googlesource.com/c/1446405
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628556}
parent cd37bf32
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/window/dialog_client_view.h"
namespace ash { namespace ash {
...@@ -49,22 +48,22 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kOnlyAllowMouseClickEvents, false); ...@@ -49,22 +48,22 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kOnlyAllowMouseClickEvents, false);
// paint to a higher level in the layer tree than do direct children of // paint to a higher level in the layer tree than do direct children of
// AssistantContainerView. This allows AssistantMainView, for example, to // AssistantContainerView. This allows AssistantMainView, for example, to
// pseudo-parent overlays that draw over top of Assistant cards. // pseudo-parent overlays that draw over top of Assistant cards.
class AssistantContainerClientView : public views::DialogClientView, class AssistantContainerClientView : public views::ClientView,
public views::ViewObserver { public views::ViewObserver {
public: public:
AssistantContainerClientView(views::Widget* widget, AssistantContainerClientView(views::Widget* widget,
views::View* contents_view) views::View* contents_view)
: views::DialogClientView(widget, contents_view) {} : views::ClientView(widget, contents_view) {}
~AssistantContainerClientView() override = default; ~AssistantContainerClientView() override = default;
// views::DialogClientView: // views::ClientView:
const char* GetClassName() const override { const char* GetClassName() const override {
return "AssistantContainerClientView"; return "AssistantContainerClientView";
} }
void Layout() override { void Layout() override {
views::DialogClientView::Layout(); views::ClientView::Layout();
for (AssistantOverlay* overlay : overlays_) { for (AssistantOverlay* overlay : overlays_) {
AssistantOverlay::LayoutParams layout_params = overlay->GetLayoutParams(); AssistantOverlay::LayoutParams layout_params = overlay->GetLayoutParams();
gfx::Size preferred_size = overlay->GetPreferredSize(); gfx::Size preferred_size = overlay->GetPreferredSize();
......
...@@ -58,10 +58,13 @@ bool CaptionBar::AcceleratorPressed(const ui::Accelerator& accelerator) { ...@@ -58,10 +58,13 @@ bool CaptionBar::AcceleratorPressed(const ui::Accelerator& accelerator) {
case ui::VKEY_BROWSER_BACK: case ui::VKEY_BROWSER_BACK:
HandleButton(AssistantButtonId::kBack); HandleButton(AssistantButtonId::kBack);
break; break;
case ui::VKEY_ESCAPE:
HandleButton(AssistantButtonId::kClose);
break;
case ui::VKEY_W: case ui::VKEY_W:
if (accelerator.IsCtrlDown()) if (accelerator.IsCtrlDown()) {
HandleButton(AssistantButtonId::kClose); HandleButton(AssistantButtonId::kClose);
else { } else {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
...@@ -71,7 +74,7 @@ bool CaptionBar::AcceleratorPressed(const ui::Accelerator& accelerator) { ...@@ -71,7 +74,7 @@ bool CaptionBar::AcceleratorPressed(const ui::Accelerator& accelerator) {
return false; return false;
} }
// Don't let DialogClientView handle the accelerator. // Don't let ClientView handle the accelerator.
return true; return true;
} }
...@@ -127,9 +130,10 @@ void CaptionBar::InitLayout() { ...@@ -127,9 +130,10 @@ void CaptionBar::InitLayout() {
AssistantButtonId::kClose, this); AssistantButtonId::kClose, this);
AddChildView(close_button); AddChildView(close_button);
// Add a keyboard accelerator Ctrl + W to close Assistant UI. // Add accelerators for keyboard shortcuts that behave like caption buttons.
AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); AddAccelerator(ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_NONE)); // Back
AddAccelerator(ui::Accelerator(ui::VKEY_BROWSER_BACK, ui::EF_NONE)); AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); // Close
AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); // Close
} }
void CaptionBar::HandleButton(AssistantButtonId id) { void CaptionBar::HandleButton(AssistantButtonId id) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment