Commit 2fe3a125 authored by vasilii@chromium.org's avatar vasilii@chromium.org

Refactor BubbleDelegateView::use_focuseless().

It's confusing because it prevents the bubble activation. As a side effect on Windows the bubble doesn't get LBUTTON_DOWN messages. The reason for that is in HWNDMessageHandler::OnMouseActivate(). It asks the bubble if it can be activated. It answers "no" due to implementation in BubbleDelegateView::CanActivate(). Windows gets MA_NOACTIVATEANDEAT and MouseDown event isn't dispatched. This is definitely unexpected.
The bubbles which indeed always inactive should use set_can_activate(false) at construction time.
The bubbles which can be active but created without focus by default should use ShowInactive() instead.


BUG=392734

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285682 0039d316-1c4b-4281-b951-d872f2087c98
parent 401c9dc4
...@@ -148,7 +148,7 @@ CandidateWindowView::CandidateWindowView(gfx::NativeView parent) ...@@ -148,7 +148,7 @@ CandidateWindowView::CandidateWindowView(gfx::NativeView parent)
should_show_at_composition_head_(false), should_show_at_composition_head_(false),
should_show_upper_side_(false), should_show_upper_side_(false),
was_candidate_window_open_(false) { was_candidate_window_open_(false) {
set_use_focusless(true); set_can_activate(false);
set_parent_window(parent); set_parent_window(parent);
set_margins(gfx::Insets()); set_margins(gfx::Insets());
......
...@@ -172,7 +172,7 @@ InfolistWindow::InfolistWindow(views::View* candidate_window, ...@@ -172,7 +172,7 @@ InfolistWindow::InfolistWindow(views::View* candidate_window,
title_font_list_(gfx::Font(kJapaneseFontName, kFontSizeDelta + 15)), title_font_list_(gfx::Font(kJapaneseFontName, kFontSizeDelta + 15)),
description_font_list_(gfx::Font(kJapaneseFontName, description_font_list_(gfx::Font(kJapaneseFontName,
kFontSizeDelta + 11)) { kFontSizeDelta + 11)) {
set_use_focusless(true); set_can_activate(false);
set_accept_events(false); set_accept_events(false);
set_margins(gfx::Insets()); set_margins(gfx::Insets());
......
...@@ -48,7 +48,7 @@ ModeIndicatorView::ModeIndicatorView(gfx::NativeView parent, ...@@ -48,7 +48,7 @@ ModeIndicatorView::ModeIndicatorView(gfx::NativeView parent,
const base::string16& label) const base::string16& label)
: cursor_bounds_(cursor_bounds), : cursor_bounds_(cursor_bounds),
label_view_(new views::Label(label)) { label_view_(new views::Label(label)) {
set_use_focusless(true); set_can_activate(false);
set_accept_events(false); set_accept_events(false);
set_parent_window(parent); set_parent_window(parent);
set_shadow(views::BubbleBorder::NO_SHADOW); set_shadow(views::BubbleBorder::NO_SHADOW);
......
...@@ -84,7 +84,7 @@ PopupMessage::MessageBubble::MessageBubble(const base::string16& caption, ...@@ -84,7 +84,7 @@ PopupMessage::MessageBubble::MessageBubble(const base::string16& caption,
set_anchor_view_insets(insets); set_anchor_view_insets(insets);
set_close_on_esc(false); set_close_on_esc(false);
set_close_on_deactivate(false); set_close_on_deactivate(false);
set_use_focusless(true); set_can_activate(false);
set_accept_events(false); set_accept_events(false);
set_margins(gfx::Insets(kMessageTopBottomMargin, kMessageLeftRightMargin, set_margins(gfx::Insets(kMessageTopBottomMargin, kMessageLeftRightMargin,
......
...@@ -50,7 +50,7 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor, ...@@ -50,7 +50,7 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding));
// Overflow bubble should not get focus. If it get focus when it is shown, // Overflow bubble should not get focus. If it get focus when it is shown,
// active state item is changed to running state. // active state item is changed to running state.
set_use_focusless(true); set_can_activate(false);
// Makes bubble view has a layer and clip its children layers. // Makes bubble view has a layer and clip its children layers.
SetPaintToLayer(true); SetPaintToLayer(true);
......
...@@ -85,7 +85,7 @@ ShelfTooltipManager::ShelfTooltipBubble::ShelfTooltipBubble( ...@@ -85,7 +85,7 @@ ShelfTooltipManager::ShelfTooltipBubble::ShelfTooltipBubble(
set_anchor_view_insets(insets); set_anchor_view_insets(insets);
set_close_on_esc(false); set_close_on_esc(false);
set_close_on_deactivate(false); set_close_on_deactivate(false);
set_use_focusless(true); set_can_activate(false);
set_accept_events(false); set_accept_events(false);
set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin, set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin,
kTooltipTopBottomMargin, kTooltipLeftRightMargin)); kTooltipTopBottomMargin, kTooltipLeftRightMargin));
......
...@@ -94,7 +94,7 @@ class NetworkStateListDetailedView::InfoBubble ...@@ -94,7 +94,7 @@ class NetworkStateListDetailedView::InfoBubble
NetworkStateListDetailedView* detailed_view) NetworkStateListDetailedView* detailed_view)
: views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT), : views::BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT),
detailed_view_(detailed_view) { detailed_view_(detailed_view) {
set_use_focusless(true); set_can_activate(false);
set_parent_window(ash::Shell::GetContainer( set_parent_window(ash::Shell::GetContainer(
anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), anchor->GetWidget()->GetNativeWindow()->GetRootWindow(),
ash::kShellWindowId_SettingBubbleContainer)); ash::kShellWindowId_SettingBubbleContainer));
...@@ -106,8 +106,6 @@ class NetworkStateListDetailedView::InfoBubble ...@@ -106,8 +106,6 @@ class NetworkStateListDetailedView::InfoBubble
detailed_view_->OnInfoBubbleDestroyed(); detailed_view_->OnInfoBubbleDestroyed();
} }
virtual bool CanActivate() const OVERRIDE { return false; }
private: private:
// Not owned. // Not owned.
NetworkStateListDetailedView* detailed_view_; NetworkStateListDetailedView* detailed_view_;
......
...@@ -967,14 +967,14 @@ TEST_F(ImmersiveFullscreenControllerTest, Bubbles) { ...@@ -967,14 +967,14 @@ TEST_F(ImmersiveFullscreenControllerTest, Bubbles) {
views::BubbleDelegateView* bubble_delegate4(new views::BubbleDelegateView( views::BubbleDelegateView* bubble_delegate4(new views::BubbleDelegateView(
child_view, views::BubbleBorder::NONE)); child_view, views::BubbleBorder::NONE));
bubble_delegate4->set_use_focusless(true); bubble_delegate4->set_can_activate(false);
views::Widget* bubble_widget4(views::BubbleDelegateView::CreateBubble( views::Widget* bubble_widget4(views::BubbleDelegateView::CreateBubble(
bubble_delegate4)); bubble_delegate4));
bubble_widget4->Show(); bubble_widget4->Show();
views::BubbleDelegateView* bubble_delegate5(new views::BubbleDelegateView( views::BubbleDelegateView* bubble_delegate5(new views::BubbleDelegateView(
child_view, views::BubbleBorder::NONE)); child_view, views::BubbleBorder::NONE));
bubble_delegate5->set_use_focusless(true); bubble_delegate5->set_can_activate(false);
views::Widget* bubble_widget5(views::BubbleDelegateView::CreateBubble( views::Widget* bubble_widget5(views::BubbleDelegateView::CreateBubble(
bubble_delegate5)); bubble_delegate5));
bubble_widget5->Show(); bubble_widget5->Show();
......
...@@ -65,7 +65,7 @@ InfoBubble::InfoBubble(views::View* anchor, ...@@ -65,7 +65,7 @@ InfoBubble::InfoBubble(views::View* anchor,
kInfoBubbleHorizontalMargin, kInfoBubbleHorizontalMargin,
kInfoBubbleVerticalMargin, kInfoBubbleVerticalMargin,
kInfoBubbleHorizontalMargin)); kInfoBubbleHorizontalMargin));
set_use_focusless(true); set_can_activate(false);
SetLayoutManager(new views::FillLayout); SetLayoutManager(new views::FillLayout);
views::Label* label = new views::Label(message); views::Label* label = new views::Label(message);
......
...@@ -114,7 +114,7 @@ void TooltipIcon::ShowBubble() { ...@@ -114,7 +114,7 @@ void TooltipIcon::ShowBubble() {
bubble_ = new TooltipBubble(this, tooltip_); bubble_ = new TooltipBubble(this, tooltip_);
// When shown due to a gesture event, close on deactivate (i.e. don't use // When shown due to a gesture event, close on deactivate (i.e. don't use
// "focusless"). // "focusless").
bubble_->set_use_focusless(mouse_inside_); bubble_->set_can_activate(!mouse_inside_);
bubble_->Show(); bubble_->Show();
observer_.Add(bubble_->GetWidget()); observer_.Add(bubble_->GetWidget());
......
...@@ -63,21 +63,18 @@ void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, ...@@ -63,21 +63,18 @@ void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
ZoomController::FromWebContents(web_contents); ZoomController::FromWebContents(web_contents);
const extensions::Extension* extension = zoom_controller->last_extension(); const extensions::Extension* extension = zoom_controller->last_extension();
// If the bubble is already showing in this window, its |auto_close_| value // If the bubble is already showing in this window and the zoom change was not
// is equal to |auto_close|, and the zoom change was not initiated by an // initiated by an extension, then the bubble can be reused and only the label
// extension, then the bubble can be reused and only the label text needs to // text needs to be updated.
// be updated.
if (zoom_bubble_ && if (zoom_bubble_ &&
zoom_bubble_->GetAnchorView() == anchor_view && zoom_bubble_->GetAnchorView() == anchor_view &&
zoom_bubble_->auto_close_ == auto_close &&
!extension) { !extension) {
zoom_bubble_->Refresh(); zoom_bubble_->Refresh();
return; return;
} }
// If the bubble is already showing but its |auto_close_| value is not equal // If the bubble is already showing but in a different tab, the current
// to |auto_close|, the bubble's focus properties must change, so the // bubble must be closed and a new one created.
// current bubble must be closed and a new one created.
CloseBubble(); CloseBubble();
zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_bubble_ = new ZoomBubbleView(anchor_view,
...@@ -101,7 +98,7 @@ void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, ...@@ -101,7 +98,7 @@ void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
if (is_fullscreen) if (is_fullscreen)
zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen());
if (zoom_bubble_->use_focusless()) if (auto_close)
zoom_bubble_->GetWidget()->ShowInactive(); zoom_bubble_->GetWidget()->ShowInactive();
else else
zoom_bubble_->GetWidget()->Show(); zoom_bubble_->GetWidget()->Show();
...@@ -139,7 +136,6 @@ ZoomBubbleView::ZoomBubbleView( ...@@ -139,7 +136,6 @@ ZoomBubbleView::ZoomBubbleView(
immersive_mode_controller_(immersive_mode_controller) { immersive_mode_controller_(immersive_mode_controller) {
// Compensate for built-in vertical padding in the anchor view's image. // Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
set_use_focusless(auto_close);
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
// Add observers to close the bubble if the fullscreen state or immersive // Add observers to close the bubble if the fullscreen state or immersive
...@@ -250,12 +246,10 @@ void ZoomBubbleView::OnExtensionIconImageChanged( ...@@ -250,12 +246,10 @@ void ZoomBubbleView::OnExtensionIconImageChanged(
} }
void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) { void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
set_use_focusless(false);
StopTimer(); StopTimer();
} }
void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) { void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) {
set_use_focusless(auto_close_);
StartTimerIfNecessary(); StartTimerIfNecessary();
} }
...@@ -265,9 +259,8 @@ void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { ...@@ -265,9 +259,8 @@ void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) {
return; return;
} }
// If an auto-closing bubble was tapped, show a non-auto-closing bubble in auto_close_ = false;
// its place. StopTimer();
ShowBubble(zoom_bubble_->web_contents_, false);
event->SetHandled(); event->SetHandled();
} }
......
...@@ -538,13 +538,7 @@ void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, ...@@ -538,13 +538,7 @@ void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
manage_passwords_bubble_->AdjustForFullscreen( manage_passwords_bubble_->AdjustForFullscreen(
browser_view->GetBoundsInScreen()); browser_view->GetBoundsInScreen());
} }
manage_passwords_bubble_->GetWidget()->Show(); manage_passwords_bubble_->GetWidget()->ShowInactive();
// set_use_focusless(true) has adverse effect on Windows.
// 1) The bubble can't be the active window (which is not desired behavior).
// 2) The bubble doesn't get WM_LBUTTONDOWN event. Therefore, all the buttons
// get stuck.
// TODO(vasilii): remove this line once the bug in infrastructure is resolved.
manage_passwords_bubble_->set_use_focusless(false);
} }
// static // static
...@@ -572,8 +566,6 @@ ManagePasswordsBubbleView::ManagePasswordsBubbleView( ...@@ -572,8 +566,6 @@ ManagePasswordsBubbleView::ManagePasswordsBubbleView(
never_save_passwords_(false) { never_save_passwords_(false) {
// Compensate for built-in vertical padding in the anchor view's image. // Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
// Don't focus by default.
set_use_focusless(true);
if (anchor_view) if (anchor_view)
anchor_view->SetActive(true); anchor_view->SetActive(true);
} }
......
...@@ -24,7 +24,7 @@ ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate( ...@@ -24,7 +24,7 @@ ValidationMessageBubbleDelegate::ValidationMessageBubbleDelegate(
const base::string16& sub_text, const base::string16& sub_text,
Observer* observer) Observer* observer)
: observer_(observer), width_(0), height_(0) { : observer_(observer), width_(0), height_(0) {
set_use_focusless(true); set_can_activate(false);
set_arrow(views::BubbleBorder::TOP_LEFT); set_arrow(views::BubbleBorder::TOP_LEFT);
SetAnchorRect(anchor_in_screen); SetAnchorRect(anchor_in_screen);
......
...@@ -54,7 +54,7 @@ BubbleDelegateView::BubbleDelegateView() ...@@ -54,7 +54,7 @@ BubbleDelegateView::BubbleDelegateView()
shadow_(BubbleBorder::SMALL_SHADOW), shadow_(BubbleBorder::SMALL_SHADOW),
color_explicitly_set_(false), color_explicitly_set_(false),
margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
use_focusless_(false), can_activate_(true),
accept_events_(true), accept_events_(true),
border_accepts_events_(true), border_accepts_events_(true),
adjust_if_offscreen_(true), adjust_if_offscreen_(true),
...@@ -74,7 +74,7 @@ BubbleDelegateView::BubbleDelegateView( ...@@ -74,7 +74,7 @@ BubbleDelegateView::BubbleDelegateView(
shadow_(BubbleBorder::SMALL_SHADOW), shadow_(BubbleBorder::SMALL_SHADOW),
color_explicitly_set_(false), color_explicitly_set_(false),
margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin),
use_focusless_(false), can_activate_(true),
accept_events_(true), accept_events_(true),
border_accepts_events_(true), border_accepts_events_(true),
adjust_if_offscreen_(true), adjust_if_offscreen_(true),
...@@ -118,7 +118,7 @@ BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { ...@@ -118,7 +118,7 @@ BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() {
} }
bool BubbleDelegateView::CanActivate() const { bool BubbleDelegateView::CanActivate() const {
return !use_focusless(); return can_activate();
} }
bool BubbleDelegateView::ShouldShowCloseButton() const { bool BubbleDelegateView::ShouldShowCloseButton() const {
......
...@@ -83,8 +83,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, ...@@ -83,8 +83,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
gfx::NativeView parent_window() const { return parent_window_; } gfx::NativeView parent_window() const { return parent_window_; }
void set_parent_window(gfx::NativeView window) { parent_window_ = window; } void set_parent_window(gfx::NativeView window) { parent_window_ = window; }
bool use_focusless() const { return use_focusless_; } bool can_activate() const { return can_activate_; }
void set_use_focusless(bool focusless) { use_focusless_ = focusless; } void set_can_activate(bool focusless) { can_activate_ = focusless; }
bool accept_events() const { return accept_events_; } bool accept_events() const { return accept_events_; }
void set_accept_events(bool accept_events) { accept_events_ = accept_events; } void set_accept_events(bool accept_events) { accept_events_ = accept_events; }
...@@ -183,8 +183,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, ...@@ -183,8 +183,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// Insets applied to the |anchor_view_| bounds. // Insets applied to the |anchor_view_| bounds.
gfx::Insets anchor_view_insets_; gfx::Insets anchor_view_insets_;
// If true, the bubble does not take focus on display; default is false. // If false, the bubble can't be activated; default is true.
bool use_focusless_; bool can_activate_;
// Specifies whether the bubble (or its border) handles mouse events, etc. // Specifies whether the bubble (or its border) handles mouse events, etc.
bool accept_events_; bool accept_events_;
......
...@@ -47,7 +47,7 @@ TouchEditingMenuView::TouchEditingMenuView( ...@@ -47,7 +47,7 @@ TouchEditingMenuView::TouchEditingMenuView(
set_shadow(views::BubbleBorder::SMALL_SHADOW); set_shadow(views::BubbleBorder::SMALL_SHADOW);
set_parent_window(context); set_parent_window(context);
set_margins(gfx::Insets(kMenuMargin, kMenuMargin, kMenuMargin, kMenuMargin)); set_margins(gfx::Insets(kMenuMargin, kMenuMargin, kMenuMargin, kMenuMargin));
set_use_focusless(true); set_can_activate(false);
set_adjust_if_offscreen(true); set_adjust_if_offscreen(true);
SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0, SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 0, 0,
......
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