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

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
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a18c08888d20d3a2d1154053073c25be19b34327..a893bcf23268a16c9b54f8c428cdc24e021e15dc 100644
--- a/ui/views/bubble/bubble_delegate.cc
+++ b/ui/views/bubble/bubble_dialog_delegate.cc
@@ -1,12 +1,11 @@
-// 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"
-#include "ui/base/default_style.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
@@ -16,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"
@@ -26,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;
@@ -36,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)
@@ -48,36 +49,10 @@ Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
} // namespace
// static
-const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView";
+const char BubbleDialogDelegateView::kViewClassName[] =
+ "BubbleDialogDelegateView";
-BubbleDelegateView::BubbleDelegateView()
- : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
-
-BubbleDelegateView::BubbleDelegateView(View* anchor_view,
- BubbleBorder::Arrow arrow)
- : close_on_esc_(true),
- close_on_deactivate_(true),
- anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
- anchor_widget_(NULL),
- arrow_(arrow),
- shadow_(BubbleBorder::SMALL_SHADOW),
- color_explicitly_set_(false),
- margins_(kPanelVertMargin,
- kPanelHorizMargin,
- kPanelVertMargin,
- kPanelHorizMargin),
- accept_events_(true),
- border_accepts_events_(true),
- adjust_if_offscreen_(true),
- parent_window_(NULL),
- close_reason_(CloseReason::UNKNOWN) {
- if (anchor_view)
- SetAnchorView(anchor_view);
- AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
- UpdateColorsFromTheme(GetNativeTheme());
-}
-
-BubbleDelegateView::~BubbleDelegateView() {
+BubbleDialogDelegateView::~BubbleDialogDelegateView() {
if (GetWidget())
GetWidget()->RemoveObserver(this);
SetLayoutManager(NULL);
@@ -85,7 +60,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());
@@ -107,19 +83,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());
+ return client;
}
-NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView(
+NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView(
Widget* widget) {
BubbleFrameView* frame = new BubbleFrameView(
gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin),
@@ -137,15 +111,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()) {
@@ -153,13 +127,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
@@ -168,15 +142,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;
@@ -184,17 +158,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_;
@@ -203,35 +178,73 @@ gfx::Rect BubbleDelegateView::GetAnchorRect() const {
return anchor_rect_;
}
-void BubbleDelegateView::OnBeforeBubbleWidgetInit(Widget::InitParams* params,
- Widget* widget) const {
-}
+void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit(
+ Widget::InitParams* params,
+ Widget* widget) const {}
-scoped_ptr<View> BubbleDelegateView::CreateFootnoteView() {
- return nullptr;
-}
-
-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(
+BubbleDialogDelegateView::BubbleDialogDelegateView()
+ : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
+
+BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view,
+ BubbleBorder::Arrow arrow)
+ : close_on_esc_(true),
+ close_on_deactivate_(true),
+ anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
+ anchor_widget_(NULL),
+ arrow_(arrow),
+ shadow_(BubbleBorder::SMALL_SHADOW),
+ color_explicitly_set_(false),
+ margins_(kPanelVertMargin,
+ kPanelHorizMargin,
+ kPanelVertMargin,
+ kPanelHorizMargin),
+ accept_events_(true),
+ border_accepts_events_(true),
+ adjust_if_offscreen_(true),
+ parent_window_(NULL),
+ close_reason_(CloseReason::UNKNOWN) {
+ if (anchor_view)
+ SetAnchorView(anchor_view);
+ AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
+ UpdateColorsFromTheme(GetNativeTheme());
+}
+
+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(), GetWidget()->client_view()->GetPreferredSize(),
+ adjust_if_offscreen_ && !anchor_minimized);
+}
+
+const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ return rb.GetFontList(ui::ResourceBundle::MediumFont);
+}
+
+bool BubbleDialogDelegateView::AcceleratorPressed(
const ui::Accelerator& accelerator) {
if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
return false;
@@ -240,13 +253,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()) {
@@ -276,36 +290,24 @@ 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() {
- // 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);
-}
-
-const gfx::FontList& BubbleDelegateView::GetTitleFontList() const {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- return rb.GetFontListWithDelta(ui::kTitleFontSizeDelta);
-}
-
-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)
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698