Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: ui/views/bubble/bubble_dialog_delegate.cc

Issue 1717453003: Introduce BubbleDialogDelegateView, which extends DialogDelegateView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/bubble/bubble_dialog_delegate.cc
diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_dialog_delegate.cc
similarity index 70%
copy from ui/views/bubble/bubble_delegate.cc
copy to ui/views/bubble/bubble_dialog_delegate.cc
index 5e30b98694a5a4760385970dd2635c2cf374afb6..2de96e72d96a82c026416db5580a12a2ac37ac09 100644
--- a/ui/views/bubble/bubble_delegate.cc
+++ b/ui/views/bubble/bubble_dialog_delegate.cc
@@ -1,8 +1,8 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/views/bubble/bubble_delegate.h"
+#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_view_state.h"
@@ -15,6 +15,7 @@
#include "ui/views/layout/layout_constants.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
+#include "ui/views/window/dialog_client_view.h"
#if defined(OS_WIN)
#include "ui/base/win/shell.h"
@@ -25,7 +26,7 @@ namespace views {
namespace {
// Create a widget to host the bubble.
-Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
+Widget* CreateBubbleWidget(BubbleDialogDelegateView* bubble) {
Widget* bubble_widget = new Widget();
Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE);
bubble_params.delegate = bubble;
@@ -35,8 +36,9 @@ Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
bubble_params.parent = bubble->parent_window();
else if (bubble->anchor_widget())
bubble_params.parent = bubble->anchor_widget()->GetNativeView();
- bubble_params.activatable = bubble->CanActivate() ?
- Widget::InitParams::ACTIVATABLE_YES : Widget::InitParams::ACTIVATABLE_NO;
+ bubble_params.activatable = bubble->CanActivate()
+ ? Widget::InitParams::ACTIVATABLE_YES
+ : Widget::InitParams::ACTIVATABLE_NO;
bubble->OnBeforeBubbleWidgetInit(&bubble_params, bubble_widget);
bubble_widget->Init(bubble_params);
if (bubble_params.parent)
@@ -47,13 +49,14 @@ Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
} // namespace
// static
-const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView";
+const char BubbleDialogDelegateView::kViewClassName[] =
+ "BubbleDialogDelegateView";
-BubbleDelegateView::BubbleDelegateView()
- : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
+BubbleDialogDelegateView::BubbleDialogDelegateView()
msw 2016/02/22 21:43:56 nit: reorder to match decl (ditto for other ctor)
Evan Stade 2016/02/22 22:58:23 Done.
+ : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
-BubbleDelegateView::BubbleDelegateView(View* anchor_view,
- BubbleBorder::Arrow arrow)
+BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view,
+ BubbleBorder::Arrow arrow)
: close_on_esc_(true),
close_on_deactivate_(true),
anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
@@ -76,7 +79,7 @@ BubbleDelegateView::BubbleDelegateView(View* anchor_view,
UpdateColorsFromTheme(GetNativeTheme());
}
-BubbleDelegateView::~BubbleDelegateView() {
+BubbleDialogDelegateView::~BubbleDialogDelegateView() {
if (GetWidget())
GetWidget()->RemoveObserver(this);
SetLayoutManager(NULL);
@@ -84,7 +87,8 @@ BubbleDelegateView::~BubbleDelegateView() {
}
// static
-Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
+Widget* BubbleDialogDelegateView::CreateBubble(
+ BubbleDialogDelegateView* bubble_delegate) {
bubble_delegate->Init();
// Get the latest anchor widget from the anchor view at bubble creation time.
bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView());
@@ -106,19 +110,17 @@ Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
return bubble_widget;
}
-BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() {
- return this;
-}
-
-bool BubbleDelegateView::ShouldShowCloseButton() const {
+bool BubbleDialogDelegateView::ShouldShowCloseButton() const {
return false;
}
-View* BubbleDelegateView::GetContentsView() {
- return this;
+ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) {
+ DialogClientView* client = new DialogClientView(widget, GetContentsView());
+ client->set_button_row_insets(gfx::Insets());
msw 2016/02/22 21:43:56 Why do we want empty insets here?
Evan Stade 2016/02/22 22:58:23 Dialogs don't inset the client view at all. Bubble
msw 2016/02/22 23:24:57 Acknowledged.
+ return client;
}
-NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
+NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView(
Widget* widget) {
BubbleFrameView* frame = new BubbleFrameView(
gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin),
@@ -136,15 +138,15 @@ NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
return frame;
}
-void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) {
+void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) {
state->role = ui::AX_ROLE_DIALOG;
}
-const char* BubbleDelegateView::GetClassName() const {
+const char* BubbleDialogDelegateView::GetClassName() const {
return kViewClassName;
}
-void BubbleDelegateView::OnWidgetClosing(Widget* widget) {
+void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) {
DCHECK(GetBubbleFrameView());
if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN &&
GetBubbleFrameView()->close_button_clicked()) {
@@ -152,13 +154,13 @@ void BubbleDelegateView::OnWidgetClosing(Widget* widget) {
}
}
-void BubbleDelegateView::OnWidgetDestroying(Widget* widget) {
+void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) {
if (anchor_widget() == widget)
SetAnchorView(NULL);
}
-void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
- bool visible) {
+void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget,
+ bool visible) {
#if defined(OS_WIN)
// On Windows we need to handle this before the bubble is visible or hidden.
// Please see the comment on the OnWidgetVisibilityChanging function. On
@@ -167,15 +169,15 @@ void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget,
#endif
}
-void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget,
- bool visible) {
+void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget,
+ bool visible) {
#if !defined(OS_WIN)
HandleVisibilityChanged(widget, visible);
#endif
}
-void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget,
- bool active) {
+void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget,
+ bool active) {
if (close_on_deactivate() && widget == GetWidget() && !active) {
if (close_reason_ == CloseReason::UNKNOWN)
close_reason_ = CloseReason::DEACTIVATION;
@@ -183,17 +185,18 @@ void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget,
}
}
-void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget,
- const gfx::Rect& new_bounds) {
+void BubbleDialogDelegateView::OnWidgetBoundsChanged(
+ Widget* widget,
+ const gfx::Rect& new_bounds) {
if (GetBubbleFrameView() && anchor_widget() == widget)
SizeToContents();
}
-View* BubbleDelegateView::GetAnchorView() const {
+View* BubbleDialogDelegateView::GetAnchorView() const {
return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
}
-gfx::Rect BubbleDelegateView::GetAnchorRect() const {
+gfx::Rect BubbleDialogDelegateView::GetAnchorRect() const {
if (!GetAnchorView())
return anchor_rect_;
@@ -202,35 +205,32 @@ gfx::Rect BubbleDelegateView::GetAnchorRect() const {
return anchor_rect_;
}
-void BubbleDelegateView::OnBeforeBubbleWidgetInit(Widget::InitParams* params,
- Widget* widget) const {
-}
-
-scoped_ptr<View> BubbleDelegateView::CreateFootnoteView() {
- return nullptr;
-}
+void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit(
+ Widget::InitParams* params,
+ Widget* widget) const {}
-void BubbleDelegateView::UseCompactMargins() {
+void BubbleDialogDelegateView::UseCompactMargins() {
const int kCompactMargin = 6;
margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin);
}
-void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) {
+void BubbleDialogDelegateView::SetAlignment(
+ BubbleBorder::BubbleAlignment alignment) {
GetBubbleFrameView()->bubble_border()->set_alignment(alignment);
SizeToContents();
}
-void BubbleDelegateView::SetArrowPaintType(
+void BubbleDialogDelegateView::SetArrowPaintType(
BubbleBorder::ArrowPaintType paint_type) {
GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type);
SizeToContents();
}
-void BubbleDelegateView::OnAnchorBoundsChanged() {
+void BubbleDialogDelegateView::OnAnchorBoundsChanged() {
SizeToContents();
}
-bool BubbleDelegateView::AcceleratorPressed(
+bool BubbleDialogDelegateView::AcceleratorPressed(
const ui::Accelerator& accelerator) {
if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
return false;
@@ -239,13 +239,14 @@ bool BubbleDelegateView::AcceleratorPressed(
return true;
}
-void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
+void BubbleDialogDelegateView::OnNativeThemeChanged(
+ const ui::NativeTheme* theme) {
UpdateColorsFromTheme(theme);
}
-void BubbleDelegateView::Init() {}
+void BubbleDialogDelegateView::Init() {}
-void BubbleDelegateView::SetAnchorView(View* anchor_view) {
+void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) {
// When the anchor view gets set the associated anchor widget might
// change as well.
if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) {
@@ -275,37 +276,38 @@ void BubbleDelegateView::SetAnchorView(View* anchor_view) {
OnAnchorBoundsChanged();
}
-void BubbleDelegateView::SetAnchorRect(const gfx::Rect& rect) {
+void BubbleDialogDelegateView::SetAnchorRect(const gfx::Rect& rect) {
anchor_rect_ = rect;
if (GetWidget())
OnAnchorBoundsChanged();
}
-void BubbleDelegateView::SizeToContents() {
+void BubbleDialogDelegateView::SizeToContents() {
GetWidget()->SetBounds(GetBubbleBounds());
}
-BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const {
+BubbleFrameView* BubbleDialogDelegateView::GetBubbleFrameView() const {
const NonClientView* view =
GetWidget() ? GetWidget()->non_client_view() : NULL;
return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL;
}
-gfx::Rect BubbleDelegateView::GetBubbleBounds() {
+gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() {
// The argument rect has its origin at the bubble's arrow anchor point;
// its size is the preferred size of the bubble's client view (this view).
bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized();
- return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(),
- GetPreferredSize(), adjust_if_offscreen_ && !anchor_minimized);
+ return GetBubbleFrameView()->GetUpdatedWindowBounds(
+ GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(),
+ adjust_if_offscreen_ && !anchor_minimized);
}
-const gfx::FontList& BubbleDelegateView::GetTitleFontList() const {
+const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return rb.GetFontList(ui::ResourceBundle::MediumFont);
}
-
-void BubbleDelegateView::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
+void BubbleDialogDelegateView::UpdateColorsFromTheme(
+ const ui::NativeTheme* theme) {
if (!color_explicitly_set_)
color_ = theme->GetSystemColor(ui::NativeTheme::kColorId_BubbleBackground);
set_background(Background::CreateSolidBackground(color()));
@@ -314,7 +316,8 @@ void BubbleDelegateView::UpdateColorsFromTheme(const ui::NativeTheme* theme) {
frame_view->bubble_border()->set_background_color(color());
}
-void BubbleDelegateView::HandleVisibilityChanged(Widget* widget, bool visible) {
+void BubbleDialogDelegateView::HandleVisibilityChanged(Widget* widget,
+ bool visible) {
if (widget == GetWidget() && anchor_widget() &&
anchor_widget()->GetTopLevelWidget()) {
if (visible)

Powered by Google App Engine
This is Rietveld 408576698