Skip to content

Commit

Permalink
Revert "Put the close button of a notification into focus chain."
Browse files Browse the repository at this point in the history
This reverts commit 87b724b
on branch 2987 to make PFQ happy.

BUG=682868, 661105
TBR=yoshiki@chromium.org

Review-Url: https://codereview.chromium.org/2644383002 .
Cr-Commit-Position: refs/branch-heads/2987@{#4}
Cr-Branched-From: ad51088-refs/heads/master@{#444943}
  • Loading branch information
Xiyuan Xia committed Jan 20, 2017
1 parent 0fbdde6 commit 921ef9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 61 deletions.
86 changes: 28 additions & 58 deletions ui/arc/notification/arc_custom_notification_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/painter.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"

Expand Down Expand Up @@ -178,49 +176,6 @@ class ArcCustomNotificationView::ContentViewDelegate
DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate);
};

class ArcCustomNotificationView::CloseButton : public views::ImageButton {
public:
explicit CloseButton(ArcCustomNotificationView* owner)
: views::ImageButton(owner), owner_(owner) {
set_background(
views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
SetFocusForPlatform();
SetFocusPainter(views::Painter::CreateSolidFocusPainter(
message_center::kFocusBorderColor, gfx::Insets(1, 2, 2, 2)));

// The sizes below are in DIPs.
constexpr int kPaddingFromBorder = 4;
constexpr int kImageSize = 16;
constexpr int kTouchExtendedPadding =
message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
SetBorder(
views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
kTouchExtendedPadding, kPaddingFromBorder));

ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SetImage(views::CustomButton::STATE_NORMAL,
rb.GetImageSkiaNamed(IDR_ARC_NOTIFICATION_CLOSE));
set_animate_on_state_change(false);
SetAccessibleName(l10n_util::GetStringUTF16(
IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
SetTooltipText(l10n_util::GetStringUTF16(
IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));
}

void OnFocus() override {
views::ImageButton::OnFocus();
owner_->UpdateCloseButtonVisiblity();
}

void OnBlur() override {
views::ImageButton::OnBlur();
owner_->UpdateCloseButtonVisiblity();
}

private:
ArcCustomNotificationView* const owner_;
};

ArcCustomNotificationView::ArcCustomNotificationView(
ArcCustomNotificationItem* item)
: item_(item),
Expand Down Expand Up @@ -262,7 +217,34 @@ void ArcCustomNotificationView::CreateFloatingCloseButton() {
if (!surface_)
return;

floating_close_button_ = new CloseButton(this);
// TODO(yhanada): Make the close button get focus after the entire
// notification
floating_close_button_ = new views::ImageButton(this);
floating_close_button_->set_background(
views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
floating_close_button_->SetFocusForPlatform();
floating_close_button_->SetFocusPainter(
views::Painter::CreateSolidFocusPainter(message_center::kFocusBorderColor,
gfx::Insets(1, 2, 2, 2)));

// The sizes below are in DIPs.
constexpr int kPaddingFromBorder = 4;
constexpr int kImageSize = 16;
constexpr int kTouchExtendedPadding =
message_center::kControlButtonSize - kImageSize - kPaddingFromBorder;
floating_close_button_->SetBorder(
views::CreateEmptyBorder(kPaddingFromBorder, kTouchExtendedPadding,
kTouchExtendedPadding, kPaddingFromBorder));

ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
floating_close_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetImageSkiaNamed(IDR_ARC_NOTIFICATION_CLOSE));
floating_close_button_->set_animate_on_state_change(false);
floating_close_button_->SetAccessibleName(l10n_util::GetStringUTF16(
IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME));
floating_close_button_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP));

views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
Expand All @@ -273,11 +255,6 @@ void ArcCustomNotificationView::CreateFloatingCloseButton() {
floating_close_button_widget_->Init(params);
floating_close_button_widget_->SetContentsView(floating_close_button_);

// Put the close button into the focus chain.
floating_close_button_widget_->SetFocusTraversableParent(
GetWidget()->GetFocusTraversable());
floating_close_button_widget_->SetFocusTraversableParentView(this);

Layout();
}

Expand Down Expand Up @@ -489,13 +466,6 @@ void ArcCustomNotificationView::OnBlur() {
->OnContentBlured();
}

views::FocusTraversable* ArcCustomNotificationView::GetFocusTraversable() {
if (floating_close_button_widget_)
return static_cast<views::internal::RootView*>(
floating_close_button_widget_->GetRootView());
return nullptr;
}

void ArcCustomNotificationView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (item_ && !item_->pinned() && sender == floating_close_button_) {
Expand Down
3 changes: 0 additions & 3 deletions ui/arc/notification/arc_custom_notification_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class NotificationSurface;
}

namespace views {
class FocusTraversable;
class ImageButton;
class Widget;
}
Expand All @@ -43,7 +42,6 @@ class ArcCustomNotificationView

private:
class ContentViewDelegate;
class CloseButton;
class EventForwarder;
class SlideHelper;

Expand All @@ -66,7 +64,6 @@ class ArcCustomNotificationView
void OnMouseExited(const ui::MouseEvent& event) override;
void OnFocus() override;
void OnBlur() override;
views::FocusTraversable* GetFocusTraversable() override;

// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
Expand Down

0 comments on commit 921ef9a

Please sign in to comment.