0

Fix broken Widget::InitParams::activatable logic as a result of https://codereview.chromium.org/286733002

This CL modifies the default return value of WidgetDelegate::CanActivate() based on the type passed into WidgetDelegate::InitParams::type
This allows whether the widget is activatable to change over time. In particular, whether the zoom bubble can be activated can change over its lifetime

BUG=353533,374095
TEST=None

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271850 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
pkotwicz@chromium.org
2014-05-21 03:45:38 +00:00
parent 70c617c73b
commit aa93d2361f
6 changed files with 31 additions and 33 deletions

@ -234,10 +234,6 @@ void ToastContentsView::WindowClosing() {
collection_->ForgetToast(this);
}
bool ToastContentsView::CanActivate() const {
return false;
}
void ToastContentsView::OnDisplayChanged() {
views::Widget* widget = GetWidget();
if (!widget)

@ -97,7 +97,6 @@ class ToastContentsView : public views::WidgetDelegateView,
// Overridden from views::WidgetDelegate:
virtual views::View* GetContentsView() OVERRIDE;
virtual void WindowClosing() OVERRIDE;
virtual bool CanActivate() const OVERRIDE;
virtual void OnDisplayChanged() OVERRIDE;
virtual void OnWorkAreaChanged() OVERRIDE;

@ -69,9 +69,7 @@ NativeWidget* CreateNativeWidget(NativeWidget* native_widget,
// WidgetDelegate is supplied.
class DefaultWidgetDelegate : public WidgetDelegate {
public:
DefaultWidgetDelegate(Widget* widget, bool can_activate)
: widget_(widget),
can_activate_(can_activate) {
explicit DefaultWidgetDelegate(Widget* widget) : widget_(widget) {
}
virtual ~DefaultWidgetDelegate() {}
@ -85,9 +83,6 @@ class DefaultWidgetDelegate : public WidgetDelegate {
virtual const Widget* GetWidget() const OVERRIDE {
return widget_;
}
virtual bool CanActivate() const OVERRIDE {
return can_activate_;
}
virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE {
// In most situations where a Widget is used without a delegate the Widget
// is used as a container, so that we want focus to advance to the top-level
@ -97,7 +92,6 @@ class DefaultWidgetDelegate : public WidgetDelegate {
private:
Widget* widget_;
bool can_activate_;
DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate);
};
@ -344,20 +338,6 @@ void Widget::Init(const InitParams& in_params) {
params.type != InitParams::TYPE_TOOLTIP);
params.top_level = is_top_level_;
if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) {
can_activate_ = (params.activatable == InitParams::ACTIVATABLE_YES);
} else if (params.type != InitParams::TYPE_CONTROL &&
params.type != InitParams::TYPE_POPUP &&
params.type != InitParams::TYPE_MENU &&
params.type != InitParams::TYPE_TOOLTIP &&
params.type != InitParams::TYPE_DRAG) {
can_activate_ = true;
params.activatable = InitParams::ACTIVATABLE_YES;
} else {
can_activate_ = false;
params.activatable = InitParams::ACTIVATABLE_NO;
}
if (params.opacity == views::Widget::InitParams::INFER_OPACITY &&
params.type != views::Widget::InitParams::TYPE_WINDOW &&
params.type != views::Widget::InitParams::TYPE_PANEL)
@ -369,8 +349,25 @@ void Widget::Init(const InitParams& in_params) {
if (params.opacity == views::Widget::InitParams::INFER_OPACITY)
params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
bool can_activate = false;
if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) {
can_activate = (params.activatable == InitParams::ACTIVATABLE_YES);
} else if (params.type != InitParams::TYPE_CONTROL &&
params.type != InitParams::TYPE_POPUP &&
params.type != InitParams::TYPE_MENU &&
params.type != InitParams::TYPE_TOOLTIP &&
params.type != InitParams::TYPE_DRAG) {
can_activate = true;
params.activatable = InitParams::ACTIVATABLE_YES;
} else {
can_activate = false;
params.activatable = InitParams::ACTIVATABLE_NO;
}
widget_delegate_ = params.delegate ?
params.delegate : new DefaultWidgetDelegate(this, can_activate_);
params.delegate : new DefaultWidgetDelegate(this);
widget_delegate_->set_can_activate(can_activate);
ownership_ = params.ownership;
native_widget_ = CreateNativeWidget(params.native_widget, this)->
AsNativeWidgetPrivate();
@ -1019,7 +1016,7 @@ bool Widget::IsDialogBox() const {
}
bool Widget::CanActivate() const {
return can_activate_ && widget_delegate_->CanActivate();
return widget_delegate_->CanActivate();
}
bool Widget::IsInactiveRenderingDisabled() const {

@ -882,9 +882,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// |saved_show_state_| is maximized.
gfx::Rect initial_restored_bounds_;
// True if the widget can be activated.
bool can_activate_;
// Focus is automatically set to the view provided by the delegate
// when the widget is shown. Set this value to false to override
// initial focus for the widget.

@ -17,7 +17,9 @@ namespace views {
////////////////////////////////////////////////////////////////////////////////
// WidgetDelegate:
WidgetDelegate::WidgetDelegate() : default_contents_view_(NULL) {
WidgetDelegate::WidgetDelegate()
: default_contents_view_(NULL),
can_activate_(true) {
}
void WidgetDelegate::OnWidgetMove() {
@ -50,7 +52,7 @@ bool WidgetDelegate::CanMaximize() const {
}
bool WidgetDelegate::CanActivate() const {
return true;
return can_activate_;
}
ui::ModalType WidgetDelegate::GetModalType() const {

@ -30,6 +30,11 @@ class VIEWS_EXPORT WidgetDelegate {
public:
WidgetDelegate();
// Sets the return value of CanActivate(). Default is true.
void set_can_activate(bool can_activate) {
can_activate_ = can_activate;
}
// Called whenever the widget's position changes.
virtual void OnWidgetMove();
@ -181,6 +186,8 @@ class VIEWS_EXPORT WidgetDelegate {
private:
View* default_contents_view_;
bool can_activate_;
DISALLOW_COPY_AND_ASSIGN(WidgetDelegate);
};