Commit b5bbc014 authored by tsergeant's avatar tsergeant Committed by Commit bot

Remove default button highlighting from extension info dialog

This dialog does not have a single call-to-action button. Additionally,
the existing highlight implementation is a side-effect of using
DialogClientView, which is not well suited to this container. This CL
changes NativeDialogContainer to use a regular ClientView, removing the
default highlighting from the dialog, and refactors the two containers
to use a common base class.

BUG=445695

Review URL: https://codereview.chromium.org/933163002

Cr-Commit-Position: refs/heads/master@{#318206}
parent 179e3007
...@@ -53,39 +53,27 @@ class AppListOverlayBackground : public views::Background { ...@@ -53,39 +53,27 @@ class AppListOverlayBackground : public views::Background {
DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground); DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground);
}; };
// The contents view for an App List Dialog, which covers the entire app list // Base container for modal dialogs. Encases a content view in a modal dialog
// and adds a close button. // with an accelerator to close on escape.
class AppListDialogContainer : public views::DialogDelegateView, class BaseDialogContainer : public views::DialogDelegateView {
public views::ButtonListener {
public: public:
AppListDialogContainer(views::View* dialog_body, BaseDialogContainer(views::View* dialog_body,
const base::Closure& close_callback) const base::Closure& close_callback)
: dialog_body_(dialog_body), : dialog_body_(dialog_body),
close_button_(NULL),
close_callback_(close_callback) { close_callback_(close_callback) {
set_background(new AppListOverlayBackground());
AddChildView(dialog_body_); AddChildView(dialog_body_);
// Since we are using a ClientView instead of a DialogClientView, we need to
close_button_ = views::BubbleFrameView::CreateCloseButton(this); // manually bind the escape key to close the dialog.
ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE);
close_button_->AddAccelerator(escape); AddAccelerator(escape);
AddChildView(close_button_);
} }
~AppListDialogContainer() override {} ~BaseDialogContainer() override {}
protected:
views::View* dialog_body() { return dialog_body_; }
private: private:
// Overridden from views::View: // Overridden from views::View:
void Layout() override {
// Margin of the close button from the top right-hand corner of the dialog.
const int kCloseButtonDialogMargin = 10;
close_button_->SetPosition(
gfx::Point(width() - close_button_->width() - kCloseButtonDialogMargin,
kCloseButtonDialogMargin));
dialog_body_->SetBoundsRect(GetContentsBounds());
views::DialogDelegateView::Layout();
}
void ViewHierarchyChanged( void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override { const ViewHierarchyChangedDetails& details) override {
views::DialogDelegateView::ViewHierarchyChanged(details); views::DialogDelegateView::ViewHierarchyChanged(details);
...@@ -93,8 +81,16 @@ class AppListDialogContainer : public views::DialogDelegateView, ...@@ -93,8 +81,16 @@ class AppListDialogContainer : public views::DialogDelegateView,
GetFocusManager()->AdvanceFocus(false); GetFocusManager()->AdvanceFocus(false);
} }
bool AcceleratorPressed(const ui::Accelerator& accelerator) override {
DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE);
GetWidget()->Close();
return true;
}
// Overridden from views::DialogDelegate:
int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
// Overridden from views::WidgetDelegate: // Overridden from views::WidgetDelegate:
views::View* GetInitiallyFocusedView() override { return NULL; }
ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; } ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; }
void WindowClosing() override { void WindowClosing() override {
if (!close_callback_.is_null()) if (!close_callback_.is_null())
...@@ -103,6 +99,42 @@ class AppListDialogContainer : public views::DialogDelegateView, ...@@ -103,6 +99,42 @@ class AppListDialogContainer : public views::DialogDelegateView,
views::ClientView* CreateClientView(views::Widget* widget) override { views::ClientView* CreateClientView(views::Widget* widget) override {
return new views::ClientView(widget, GetContentsView()); return new views::ClientView(widget, GetContentsView());
} }
views::View* dialog_body_;
const base::Closure close_callback_;
DISALLOW_COPY_AND_ASSIGN(BaseDialogContainer);
};
// The contents view for an App List Dialog, which covers the entire app list
// and adds a close button.
class AppListDialogContainer : public BaseDialogContainer,
public views::ButtonListener {
public:
AppListDialogContainer(views::View* dialog_body,
const base::Closure& close_callback)
: BaseDialogContainer(dialog_body, close_callback) {
set_background(new AppListOverlayBackground());
close_button_ = views::BubbleFrameView::CreateCloseButton(this);
AddChildView(close_button_);
}
~AppListDialogContainer() override {}
private:
// Overridden from views::View:
void Layout() override {
// Margin of the close button from the top right-hand corner of the dialog.
const int kCloseButtonDialogMargin = 10;
close_button_->SetPosition(
gfx::Point(width() - close_button_->width() - kCloseButtonDialogMargin,
kCloseButtonDialogMargin));
dialog_body()->SetBoundsRect(GetContentsBounds());
views::DialogDelegateView::Layout();
}
// Overridden from views::WidgetDelegate:
views::NonClientFrameView* CreateNonClientFrameView( views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override { views::Widget* widget) override {
return new views::NativeFrameView(widget); return new views::NativeFrameView(widget);
...@@ -117,9 +149,7 @@ class AppListDialogContainer : public views::DialogDelegateView, ...@@ -117,9 +149,7 @@ class AppListDialogContainer : public views::DialogDelegateView,
} }
} }
views::View* dialog_body_;
views::LabelButton* close_button_; views::LabelButton* close_button_;
const base::Closure close_callback_;
DISALLOW_COPY_AND_ASSIGN(AppListDialogContainer); DISALLOW_COPY_AND_ASSIGN(AppListDialogContainer);
}; };
...@@ -150,38 +180,22 @@ class FullSizeBubbleFrameView : public views::BubbleFrameView { ...@@ -150,38 +180,22 @@ class FullSizeBubbleFrameView : public views::BubbleFrameView {
}; };
// A container view for a native dialog, which sizes to the given fixed |size|. // A container view for a native dialog, which sizes to the given fixed |size|.
class NativeDialogContainer : public views::DialogDelegateView { class NativeDialogContainer : public BaseDialogContainer {
public: public:
NativeDialogContainer(views::View* dialog_body, NativeDialogContainer(views::View* dialog_body,
const gfx::Size& size, const gfx::Size& size,
const base::Closure& close_callback) const base::Closure& close_callback)
: size_(size), : BaseDialogContainer(dialog_body, close_callback),
dialog_body_(dialog_body), size_(size) {
close_callback_(close_callback) {
SetLayoutManager(new views::FillLayout()); SetLayoutManager(new views::FillLayout());
AddChildView(dialog_body_);
} }
~NativeDialogContainer() override {} ~NativeDialogContainer() override {}
private: private:
// Overridden from views::View: // Overridden from views::View:
gfx::Size GetPreferredSize() const override { return size_; } gfx::Size GetPreferredSize() const override { return size_; }
void ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) override {
views::DialogDelegateView::ViewHierarchyChanged(details);
if (details.is_add && details.child == this)
GetFocusManager()->AdvanceFocus(false);
}
// Overridden from views::WidgetDelegate: // Overridden from views::WidgetDelegate:
ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_WINDOW; }
void WindowClosing() override {
if (!close_callback_.is_null())
close_callback_.Run();
}
// Overridden from views::DialogDelegate:
int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; }
views::NonClientFrameView* CreateNonClientFrameView( views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override { views::Widget* widget) override {
FullSizeBubbleFrameView* frame = new FullSizeBubbleFrameView(); FullSizeBubbleFrameView* frame = new FullSizeBubbleFrameView();
...@@ -195,8 +209,6 @@ class NativeDialogContainer : public views::DialogDelegateView { ...@@ -195,8 +209,6 @@ class NativeDialogContainer : public views::DialogDelegateView {
} }
const gfx::Size size_; const gfx::Size size_;
views::View* dialog_body_;
const base::Closure close_callback_;
DISALLOW_COPY_AND_ASSIGN(NativeDialogContainer); DISALLOW_COPY_AND_ASSIGN(NativeDialogContainer);
}; };
......
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