summaryrefslogtreecommitdiffstats
path: root/ash/system
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-19 19:24:02 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-19 19:24:02 +0000
commit5911bb9d5fcfea19dccab7697bed3bcbcffdacb4 (patch)
tree58106f5e94a257f21c9c75b8035edde1ecaa12d6 /ash/system
parenta8ee29fa63f1bae24a84d5b251472025cda103ab (diff)
downloadchromium_src-5911bb9d5fcfea19dccab7697bed3bcbcffdacb4.zip
chromium_src-5911bb9d5fcfea19dccab7697bed3bcbcffdacb4.tar.gz
chromium_src-5911bb9d5fcfea19dccab7697bed3bcbcffdacb4.tar.bz2
ash: Move ActionableView and HoverHighlightView into their own files.
BUG=174228 R=jennyz@chromium.org,jamescook@chromium.org Review URL: https://chromiumcodereview.appspot.com/12218138 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183263 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/system')
-rw-r--r--ash/system/bluetooth/tray_bluetooth.cc1
-rw-r--r--ash/system/chromeos/enterprise/tray_enterprise.cc1
-rw-r--r--ash/system/chromeos/network/network_list_detailed_view.cc1
-rw-r--r--ash/system/chromeos/network/network_list_detailed_view_base.cc1
-rw-r--r--ash/system/chromeos/network/network_list_detailed_view_base.h3
-rw-r--r--ash/system/chromeos/network/network_state_list_detailed_view.cc2
-rw-r--r--ash/system/chromeos/network/network_state_list_detailed_view.h1
-rw-r--r--ash/system/date/date_view.cc1
-rw-r--r--ash/system/date/date_view.h2
-rw-r--r--ash/system/drive/tray_drive.cc4
-rw-r--r--ash/system/ime/tray_ime.cc2
-rw-r--r--ash/system/settings/tray_settings.cc4
-rw-r--r--ash/system/tray/actionable_view.cc71
-rw-r--r--ash/system/tray/actionable_view.h60
-rw-r--r--ash/system/tray/hover_highlight_view.cc169
-rw-r--r--ash/system/tray/hover_highlight_view.h88
-rw-r--r--ash/system/tray/special_popup_row.cc1
-rw-r--r--ash/system/tray/tray_background_view.h6
-rw-r--r--ash/system/tray/tray_item_more.h2
-rw-r--r--ash/system/tray/tray_views.cc205
-rw-r--r--ash/system/tray/tray_views.h107
-rw-r--r--ash/system/tray_accessibility.cc2
-rw-r--r--ash/system/tray_accessibility.h3
-rw-r--r--ash/system/tray_caps_lock.cc2
-rw-r--r--ash/system/web_notification/web_notification_tray.cc1
-rw-r--r--ash/system/web_notification/web_notification_tray.h5
26 files changed, 420 insertions, 325 deletions
diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc
index a6c7acb..b12f0b2 100644
--- a/ash/system/bluetooth/tray_bluetooth.cc
+++ b/ash/system/bluetooth/tray_bluetooth.cc
@@ -5,6 +5,7 @@
#include "ash/system/bluetooth/tray_bluetooth.h"
#include "ash/shell.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
diff --git a/ash/system/chromeos/enterprise/tray_enterprise.cc b/ash/system/chromeos/enterprise/tray_enterprise.cc
index f9ad049..208bd83 100644
--- a/ash/system/chromeos/enterprise/tray_enterprise.cc
+++ b/ash/system/chromeos/enterprise/tray_enterprise.cc
@@ -4,6 +4,7 @@
#include "ash/system/chromeos/enterprise/tray_enterprise.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
diff --git a/ash/system/chromeos/network/network_list_detailed_view.cc b/ash/system/chromeos/network/network_list_detailed_view.cc
index f391bc8..17ea3c0 100644
--- a/ash/system/chromeos/network/network_list_detailed_view.cc
+++ b/ash/system/chromeos/network/network_list_detailed_view.cc
@@ -5,6 +5,7 @@
#include "ash/system/chromeos/network/network_list_detailed_view.h"
#include "ash/shell.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "grit/ash_resources.h"
diff --git a/ash/system/chromeos/network/network_list_detailed_view_base.cc b/ash/system/chromeos/network/network_list_detailed_view_base.cc
index 74a1b11..00b792e 100644
--- a/ash/system/chromeos/network/network_list_detailed_view_base.cc
+++ b/ash/system/chromeos/network/network_list_detailed_view_base.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_item.h"
diff --git a/ash/system/chromeos/network/network_list_detailed_view_base.h b/ash/system/chromeos/network/network_list_detailed_view_base.h
index 89f7467..b205a6f 100644
--- a/ash/system/chromeos/network/network_list_detailed_view_base.h
+++ b/ash/system/chromeos/network/network_list_detailed_view_base.h
@@ -19,6 +19,9 @@ namespace ash {
struct NetworkIconInfo;
namespace internal {
+
+class HoverHighlightView;
+
namespace tray {
// Base class for the NetworkListDetailedView and VpnListDetailedView.
diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.cc b/ash/system/chromeos/network/network_state_list_detailed_view.cc
index 4ea2046..4678411 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.cc
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.cc
@@ -10,11 +10,11 @@
#include "ash/system/chromeos/network/network_icon.h"
#include "ash/system/chromeos/network/network_icon_animation.h"
#include "ash/system/chromeos/network/tray_network.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_details_view.h"
-#include "ash/system/tray/tray_views.h"
#include "base/utf_string_conversions.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_state.h"
diff --git a/ash/system/chromeos/network/network_state_list_detailed_view.h b/ash/system/chromeos/network/network_state_list_detailed_view.h
index 787e47c..1b19518 100644
--- a/ash/system/chromeos/network/network_state_list_detailed_view.h
+++ b/ash/system/chromeos/network/network_state_list_detailed_view.h
@@ -28,6 +28,7 @@ class BubbleDelegateView;
namespace ash {
namespace internal {
+class HoverHighlightView;
class TrayNetwork;
namespace tray {
diff --git a/ash/system/date/date_view.cc b/ash/system/date/date_view.cc
index fd7fad0..8de730c 100644
--- a/ash/system/date/date_view.cc
+++ b/ash/system/date/date_view.cc
@@ -7,6 +7,7 @@
#include "ash/shell.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
+#include "ash/system/tray/tray_views.h"
#include "base/i18n/time_formatting.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
diff --git a/ash/system/date/date_view.h b/ash/system/date/date_view.h
index 43f3baa..6809461 100644
--- a/ash/system/date/date_view.h
+++ b/ash/system/date/date_view.h
@@ -6,7 +6,7 @@
#define ASH_SYSTEM_DATE_DATE_VIEW_H_
#include "ash/system/date/tray_date.h"
-#include "ash/system/tray/tray_views.h"
+#include "ash/system/tray/actionable_view.h"
#include "base/i18n/time_formatting.h"
#include "base/timer.h"
#include "ui/views/view.h"
diff --git a/ash/system/drive/tray_drive.cc b/ash/system/drive/tray_drive.cc
index 1ebda4f..2a2efac 100644
--- a/ash/system/drive/tray_drive.cc
+++ b/ash/system/drive/tray_drive.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "ash/shell.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
@@ -14,11 +15,10 @@
#include "ash/system/tray/tray_details_view.h"
#include "ash/system/tray/tray_item_more.h"
#include "ash/system/tray/tray_item_view.h"
-#include "ash/system/tray/tray_views.h"
#include "base/logging.h"
+#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
-#include "base/stl_util.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
diff --git a/ash/system/ime/tray_ime.cc b/ash/system/ime/tray_ime.cc
index faff3de..c9a92bb 100644
--- a/ash/system/ime/tray_ime.cc
+++ b/ash/system/ime/tray_ime.cc
@@ -8,6 +8,7 @@
#include "ash/root_window_controller.h"
#include "ash/shell.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
@@ -16,7 +17,6 @@
#include "ash/system/tray/tray_item_more.h"
#include "ash/system/tray/tray_item_view.h"
#include "ash/system/tray/tray_notification_view.h"
-#include "ash/system/tray/tray_views.h"
#include "ash/wm/shelf_layout_manager.h"
#include "base/logging.h"
#include "base/timer.h"
diff --git a/ash/system/settings/tray_settings.cc b/ash/system/settings/tray_settings.cc
index 7445e32..2580f24 100644
--- a/ash/system/settings/tray_settings.cc
+++ b/ash/system/settings/tray_settings.cc
@@ -6,11 +6,11 @@
#include "ash/shell.h"
#include "ash/system/power/power_status_view.h"
+#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_views.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "grit/ash_resources.h"
@@ -30,7 +30,7 @@ namespace internal {
namespace tray {
-class SettingsDefaultView : public ash::internal::ActionableView {
+class SettingsDefaultView : public ActionableView {
public:
explicit SettingsDefaultView(user::LoginStatus status)
: login_status_(status),
diff --git a/ash/system/tray/actionable_view.cc b/ash/system/tray/actionable_view.cc
new file mode 100644
index 0000000..b879881
--- /dev/null
+++ b/ash/system/tray/actionable_view.cc
@@ -0,0 +1,71 @@
+// Copyright 2012 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 "ash/system/tray/actionable_view.h"
+
+#include "ash/ash_constants.h"
+#include "ui/base/accessibility/accessible_view_state.h"
+#include "ui/gfx/canvas.h"
+
+namespace ash {
+namespace internal {
+
+ActionableView::ActionableView()
+ : has_capture_(false) {
+ set_focusable(true);
+}
+
+ActionableView::~ActionableView() {
+}
+
+void ActionableView::DrawBorder(gfx::Canvas* canvas, const gfx::Rect& bounds) {
+ gfx::Rect rect = bounds;
+ rect.Inset(1, 1, 3, 3);
+ canvas->DrawRect(rect, kFocusBorderColor);
+}
+
+bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) {
+ if (event.key_code() == ui::VKEY_SPACE ||
+ event.key_code() == ui::VKEY_RETURN) {
+ return PerformAction(event);
+ }
+ return false;
+}
+
+bool ActionableView::OnMousePressed(const ui::MouseEvent& event) {
+ // Return true so that this view starts capturing the events.
+ has_capture_ = true;
+ return true;
+}
+
+void ActionableView::OnMouseReleased(const ui::MouseEvent& event) {
+ if (has_capture_ && GetLocalBounds().Contains(event.location()))
+ PerformAction(event);
+}
+
+void ActionableView::OnMouseCaptureLost() {
+ has_capture_ = false;
+}
+
+void ActionableView::SetAccessibleName(const string16& name) {
+ accessible_name_ = name;
+}
+
+void ActionableView::OnPaintFocusBorder(gfx::Canvas* canvas) {
+ if (HasFocus() && (focusable() || IsAccessibilityFocusable()))
+ DrawBorder(canvas, GetLocalBounds());
+}
+
+void ActionableView::OnGestureEvent(ui::GestureEvent* event) {
+ if (event->type() == ui::ET_GESTURE_TAP && PerformAction(*event))
+ event->SetHandled();
+}
+
+void ActionableView::GetAccessibleState(ui::AccessibleViewState* state) {
+ state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
+ state->name = accessible_name_;
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/system/tray/actionable_view.h b/ash/system/tray/actionable_view.h
new file mode 100644
index 0000000..74f516c
--- /dev/null
+++ b/ash/system/tray/actionable_view.h
@@ -0,0 +1,60 @@
+// Copyright 2013 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.
+
+#ifndef ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
+#define ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
+
+#include "ash/ash_export.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/view.h"
+
+namespace ash {
+namespace internal {
+
+// A focusable view that performs an action when user clicks on it, or presses
+// enter or space when focused. Note that the action is triggered on mouse-up,
+// instead of on mouse-down. So if user presses the mouse on the view, then
+// moves the mouse out of the view and then releases, then the action will not
+// be performed.
+// Exported for SystemTray.
+class ASH_EXPORT ActionableView : public views::View {
+ public:
+ ActionableView();
+
+ virtual ~ActionableView();
+
+ void SetAccessibleName(const string16& name);
+ const string16& accessible_name() const { return accessible_name_; }
+
+ protected:
+ void DrawBorder(gfx::Canvas* canvas, const gfx::Rect& bounds);
+
+ // Performs an action when user clicks on the view (on mouse-press event), or
+ // presses a key when this view is in focus. Returns true if the event has
+ // been handled and an action was performed. Returns false otherwise.
+ virtual bool PerformAction(const ui::Event& event) = 0;
+
+ // Overridden from views::View.
+ virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
+ virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseCaptureLost() OVERRIDE;
+ virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
+ virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
+
+ // Overridden from ui::EventHandler.
+ virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
+
+ private:
+ string16 accessible_name_;
+ bool has_capture_;
+
+ DISALLOW_COPY_AND_ASSIGN(ActionableView);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
diff --git a/ash/system/tray/hover_highlight_view.cc b/ash/system/tray/hover_highlight_view.cc
new file mode 100644
index 0000000..c229245
--- /dev/null
+++ b/ash/system/tray/hover_highlight_view.cc
@@ -0,0 +1,169 @@
+// Copyright 2012 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 "ash/system/tray/hover_highlight_view.h"
+
+#include "ash/system/tray/fixed_sized_image_view.h"
+#include "ash/system/tray/tray_constants.h"
+#include "ash/system/tray/tray_views.h"
+#include "grit/ui_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/layout/fill_layout.h"
+
+namespace {
+
+const int kPopupDetailLabelExtraLeftMargin = 8;
+const int kCheckLabelPadding = 4;
+
+} // namespace
+
+namespace ash {
+namespace internal {
+
+HoverHighlightView::HoverHighlightView(ViewClickListener* listener)
+ : listener_(listener),
+ text_label_(NULL),
+ highlight_color_(kHoverBackgroundColor),
+ default_color_(0),
+ text_highlight_color_(0),
+ text_default_color_(0),
+ hover_(false),
+ expandable_(false) {
+ set_notify_enter_exit_on_child(true);
+}
+
+HoverHighlightView::~HoverHighlightView() {
+}
+
+void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image,
+ const string16& text,
+ gfx::Font::FontStyle style) {
+ SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems));
+ views::ImageView* image_view =
+ new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
+ image_view->SetImage(image);
+ AddChildView(image_view);
+
+ text_label_ = new views::Label(text);
+ text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ text_label_->SetFont(text_label_->font().DeriveFont(0, style));
+ if (text_default_color_)
+ text_label_->SetEnabledColor(text_default_color_);
+ AddChildView(text_label_);
+
+ SetAccessibleName(text);
+}
+
+views::Label* HoverHighlightView::AddLabel(const string16& text,
+ gfx::Font::FontStyle style) {
+ SetLayoutManager(new views::FillLayout());
+ text_label_ = new views::Label(text);
+ int margin = kTrayPopupPaddingHorizontal + kPopupDetailLabelExtraLeftMargin;
+ int left_margin = 0;
+ int right_margin = 0;
+ if (base::i18n::IsRTL())
+ right_margin = margin;
+ else
+ left_margin = margin;
+ text_label_->set_border(
+ views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
+ text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ text_label_->SetFont(text_label_->font().DeriveFont(0, style));
+ // Do not set alpha value in disable color. It will have issue with elide
+ // blending filter in disabled state for rendering label text color.
+ text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
+ if (text_default_color_)
+ text_label_->SetEnabledColor(text_default_color_);
+ AddChildView(text_label_);
+
+ SetAccessibleName(text);
+ return text_label_;
+}
+
+views::Label* HoverHighlightView::AddCheckableLabel(const string16& text,
+ gfx::Font::FontStyle style,
+ bool checked) {
+ if (checked) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ const gfx::ImageSkia* check =
+ rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia();
+ int margin = kTrayPopupPaddingHorizontal + kPopupDetailLabelExtraLeftMargin
+ - kCheckLabelPadding;
+ SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kHorizontal, 0, 3, kCheckLabelPadding));
+ views::ImageView* image_view = new FixedSizedImageView(margin, 0);
+ image_view->SetImage(check);
+ image_view->SetHorizontalAlignment(views::ImageView::TRAILING);
+ AddChildView(image_view);
+
+ text_label_ = new views::Label(text);
+ text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ text_label_->SetFont(text_label_->font().DeriveFont(0, style));
+ text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0));
+ if (text_default_color_)
+ text_label_->SetEnabledColor(text_default_color_);
+ AddChildView(text_label_);
+
+ SetAccessibleName(text);
+ return text_label_;
+ }
+ return AddLabel(text, style);
+}
+
+void HoverHighlightView::SetExpandable(bool expandable) {
+ if (expandable != expandable_) {
+ expandable_ = expandable;
+ InvalidateLayout();
+ }
+}
+
+bool HoverHighlightView::PerformAction(const ui::Event& event) {
+ if (!listener_)
+ return false;
+ listener_->ClickedOn(this);
+ return true;
+}
+
+gfx::Size HoverHighlightView::GetPreferredSize() {
+ gfx::Size size = ActionableView::GetPreferredSize();
+ if (!expandable_ || size.height() < kTrayPopupItemHeight)
+ size.set_height(kTrayPopupItemHeight);
+ return size;
+}
+
+void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) {
+ hover_ = true;
+ if (text_highlight_color_ && text_label_)
+ text_label_->SetEnabledColor(text_highlight_color_);
+ SchedulePaint();
+}
+
+void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) {
+ hover_ = false;
+ if (text_default_color_ && text_label_)
+ text_label_->SetEnabledColor(text_default_color_);
+ SchedulePaint();
+}
+
+void HoverHighlightView::OnEnabledChanged() {
+ for (int i = 0; i < child_count(); ++i)
+ child_at(i)->SetEnabled(enabled());
+}
+
+void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
+ canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
+}
+
+void HoverHighlightView::OnFocus() {
+ ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
+ ActionableView::OnFocus();
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/system/tray/hover_highlight_view.h b/ash/system/tray/hover_highlight_view.h
new file mode 100644
index 0000000..75a63d5
--- /dev/null
+++ b/ash/system/tray/hover_highlight_view.h
@@ -0,0 +1,88 @@
+// Copyright 2013 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.
+
+#ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
+#define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
+
+#include "ash/system/tray/actionable_view.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/gfx/font.h"
+
+namespace views {
+class Label;
+}
+
+namespace ash {
+namespace internal {
+
+class ViewClickListener;
+
+// A view that changes background color on hover, and triggers a callback in the
+// associated ViewClickListener on click. The view can also be forced to
+// maintain a fixed height.
+class HoverHighlightView : public ActionableView {
+ public:
+ explicit HoverHighlightView(ViewClickListener* listener);
+ virtual ~HoverHighlightView();
+
+ // Convenience function for adding an icon and a label. This also sets the
+ // accessible name.
+ void AddIconAndLabel(const gfx::ImageSkia& image,
+ const string16& text,
+ gfx::Font::FontStyle style);
+
+ // Convenience function for adding a label with padding on the left for a
+ // blank icon. This also sets the accessible name.
+ // Returns label after parenting it.
+ views::Label* AddLabel(const string16& text, gfx::Font::FontStyle style);
+
+ // Convenience function for adding an optional check and a label. In the
+ // absence of a check, padding is added to align with checked items.
+ // Returns label after parenting it.
+ views::Label* AddCheckableLabel(const string16& text,
+ gfx::Font::FontStyle style,
+ bool checked);
+
+ // Allows view to expand its height.
+ // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
+ void SetExpandable(bool expandable);
+
+ void set_highlight_color(SkColor color) { highlight_color_ = color; }
+ void set_default_color(SkColor color) { default_color_ = color; }
+ void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; }
+ void set_text_default_color(SkColor color) { text_default_color_ = color; }
+
+ views::Label* text_label() { return text_label_; }
+
+ bool hover() const { return hover_; }
+
+ private:
+ // Overridden from ActionableView:
+ virtual bool PerformAction(const ui::Event& event) OVERRIDE;
+
+ // Overridden from views::View.
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
+ virtual void OnEnabledChanged() OVERRIDE;
+ virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
+ virtual void OnFocus() OVERRIDE;
+
+ ViewClickListener* listener_;
+ views::Label* text_label_;
+ SkColor highlight_color_;
+ SkColor default_color_;
+ SkColor text_highlight_color_;
+ SkColor text_default_color_;
+ bool hover_;
+ bool expandable_;
+
+ DISALLOW_COPY_AND_ASSIGN(HoverHighlightView);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
diff --git a/ash/system/tray/special_popup_row.cc b/ash/system/tray/special_popup_row.cc
index dcfc400..43b27e8 100644
--- a/ash/system/tray/special_popup_row.cc
+++ b/ash/system/tray/special_popup_row.cc
@@ -4,6 +4,7 @@
#include "ash/system/tray/special_popup_row.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
#include "grit/ash_resources.h"
diff --git a/ash/system/tray/tray_background_view.h b/ash/system/tray/tray_background_view.h
index b5b14ef..8b136655 100644
--- a/ash/system/tray/tray_background_view.h
+++ b/ash/system/tray/tray_background_view.h
@@ -8,7 +8,7 @@
#include "ash/ash_export.h"
#include "ash/launcher/background_animator.h"
#include "ash/shelf_types.h"
-#include "ash/system/tray/tray_views.h"
+#include "ash/system/tray/actionable_view.h"
#include "ui/views/bubble/tray_bubble_view.h"
namespace ash {
@@ -18,12 +18,12 @@ class ShelfLayoutManager;
class StatusAreaWidget;
class TrayEventFilter;
class TrayBackground;
+
// Base class for children of StatusAreaWidget: SystemTray, WebNotificationTray.
// This class handles setting and animating the background when the Launcher
// his shown/hidden. It also inherits from ActionableView so that the tray
// items can override PerformAction when clicked on.
-
-class ASH_EXPORT TrayBackgroundView : public internal::ActionableView,
+class ASH_EXPORT TrayBackgroundView : public ActionableView,
public BackgroundAnimatorDelegate {
public:
// Base class for tray containers. Sets the border and layout. The container
diff --git a/ash/system/tray/tray_item_more.h b/ash/system/tray/tray_item_more.h
index 4a7db91..85839ad 100644
--- a/ash/system/tray/tray_item_more.h
+++ b/ash/system/tray/tray_item_more.h
@@ -5,7 +5,7 @@
#ifndef ASH_SYSTEM_TRAY_TRAY_ITEM_MORE_H_
#define ASH_SYSTEM_TRAY_TRAY_ITEM_MORE_H_
-#include "ash/system/tray/tray_views.h"
+#include "ash/system/tray/actionable_view.h"
#include "ui/views/view.h"
namespace views {
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 06f8699..6065d34 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -36,8 +36,6 @@ namespace ash {
namespace internal {
namespace {
-const int kPopupDetailLabelExtraLeftMargin = 8;
-const int kCheckLabelPadding = 4;
const int kTrayPopupLabelButtonPaddingHorizontal = 16;
const int kTrayPopupLabelButtonPaddingVertical = 8;
@@ -85,209 +83,6 @@ const int kTrayPopupLabelButtonBorderImagesHovered[] = {
}
////////////////////////////////////////////////////////////////////////////////
-// ActionableView
-
-ActionableView::ActionableView()
- : has_capture_(false) {
- set_focusable(true);
-}
-
-ActionableView::~ActionableView() {
-}
-
-void ActionableView::DrawBorder(gfx::Canvas* canvas, const gfx::Rect& bounds) {
- gfx::Rect rect = bounds;
- rect.Inset(1, 1, 3, 3);
- canvas->DrawRect(rect, kFocusBorderColor);
-}
-
-bool ActionableView::OnKeyPressed(const ui::KeyEvent& event) {
- if (event.key_code() == ui::VKEY_SPACE ||
- event.key_code() == ui::VKEY_RETURN) {
- return PerformAction(event);
- }
- return false;
-}
-
-bool ActionableView::OnMousePressed(const ui::MouseEvent& event) {
- // Return true so that this view starts capturing the events.
- has_capture_ = true;
- return true;
-}
-
-void ActionableView::OnMouseReleased(const ui::MouseEvent& event) {
- if (has_capture_ && GetLocalBounds().Contains(event.location()))
- PerformAction(event);
-}
-
-void ActionableView::OnMouseCaptureLost() {
- has_capture_ = false;
-}
-
-void ActionableView::SetAccessibleName(const string16& name) {
- accessible_name_ = name;
-}
-
-void ActionableView::OnPaintFocusBorder(gfx::Canvas* canvas) {
- if (HasFocus() && (focusable() || IsAccessibilityFocusable()))
- DrawBorder(canvas, GetLocalBounds());
-}
-
-void ActionableView::OnGestureEvent(ui::GestureEvent* event) {
- if (event->type() == ui::ET_GESTURE_TAP && PerformAction(*event))
- event->SetHandled();
-}
-
-void ActionableView::GetAccessibleState(ui::AccessibleViewState* state) {
- state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
- state->name = accessible_name_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// HoverHighlightView
-
-HoverHighlightView::HoverHighlightView(ViewClickListener* listener)
- : listener_(listener),
- text_label_(NULL),
- highlight_color_(kHoverBackgroundColor),
- default_color_(0),
- text_highlight_color_(0),
- text_default_color_(0),
- hover_(false),
- expandable_(false) {
- set_notify_enter_exit_on_child(true);
-}
-
-HoverHighlightView::~HoverHighlightView() {
-}
-
-void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image,
- const string16& text,
- gfx::Font::FontStyle style) {
- SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems));
- views::ImageView* image_view =
- new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
- image_view->SetImage(image);
- AddChildView(image_view);
-
- text_label_ = new views::Label(text);
- text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- text_label_->SetFont(text_label_->font().DeriveFont(0, style));
- if (text_default_color_)
- text_label_->SetEnabledColor(text_default_color_);
- AddChildView(text_label_);
-
- SetAccessibleName(text);
-}
-
-views::Label* HoverHighlightView::AddLabel(const string16& text,
- gfx::Font::FontStyle style) {
- SetLayoutManager(new views::FillLayout());
- text_label_ = new views::Label(text);
- int margin = kTrayPopupPaddingHorizontal + kPopupDetailLabelExtraLeftMargin;
- int left_margin = 0;
- int right_margin = 0;
- if (base::i18n::IsRTL())
- right_margin = margin;
- else
- left_margin = margin;
- text_label_->set_border(
- views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
- text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- text_label_->SetFont(text_label_->font().DeriveFont(0, style));
- // Do not set alpha value in disable color. It will have issue with elide
- // blending filter in disabled state for rendering label text color.
- text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
- if (text_default_color_)
- text_label_->SetEnabledColor(text_default_color_);
- AddChildView(text_label_);
-
- SetAccessibleName(text);
- return text_label_;
-}
-
-views::Label* HoverHighlightView::AddCheckableLabel(const string16& text,
- gfx::Font::FontStyle style,
- bool checked) {
- if (checked) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- const gfx::ImageSkia* check =
- rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia();
- int margin = kTrayPopupPaddingHorizontal + kPopupDetailLabelExtraLeftMargin
- - kCheckLabelPadding;
- SetLayoutManager(new views::BoxLayout(
- views::BoxLayout::kHorizontal, 0, 3, kCheckLabelPadding));
- views::ImageView* image_view = new FixedSizedImageView(margin, 0);
- image_view->SetImage(check);
- image_view->SetHorizontalAlignment(views::ImageView::TRAILING);
- AddChildView(image_view);
-
- text_label_ = new views::Label(text);
- text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- text_label_->SetFont(text_label_->font().DeriveFont(0, style));
- text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0));
- if (text_default_color_)
- text_label_->SetEnabledColor(text_default_color_);
- AddChildView(text_label_);
-
- SetAccessibleName(text);
- return text_label_;
- } else {
- return AddLabel(text, style);
- }
-}
-
-void HoverHighlightView::SetExpandable(bool expandable) {
- if (expandable != expandable_) {
- expandable_ = expandable;
- InvalidateLayout();
- }
-}
-
-bool HoverHighlightView::PerformAction(const ui::Event& event) {
- if (!listener_)
- return false;
- listener_->ClickedOn(this);
- return true;
-}
-
-gfx::Size HoverHighlightView::GetPreferredSize() {
- gfx::Size size = ActionableView::GetPreferredSize();
- if (!expandable_ || size.height() < kTrayPopupItemHeight)
- size.set_height(kTrayPopupItemHeight);
- return size;
-}
-
-void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) {
- hover_ = true;
- if (text_highlight_color_ && text_label_)
- text_label_->SetEnabledColor(text_highlight_color_);
- SchedulePaint();
-}
-
-void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) {
- hover_ = false;
- if (text_default_color_ && text_label_)
- text_label_->SetEnabledColor(text_default_color_);
- SchedulePaint();
-}
-
-void HoverHighlightView::OnEnabledChanged() {
- for (int i = 0; i < child_count(); ++i)
- child_at(i)->SetEnabled(enabled());
-}
-
-void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
- canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
-}
-
-void HoverHighlightView::OnFocus() {
- ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
- ActionableView::OnFocus();
-}
-
-////////////////////////////////////////////////////////////////////////////////
// FixedSizedScrollView
FixedSizedScrollView::FixedSizedScrollView() {
diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h
index 6950f91..f59c4df 100644
--- a/ash/system/tray/tray_views.h
+++ b/ash/system/tray/tray_views.h
@@ -34,119 +34,12 @@ namespace internal {
class TrayItemView;
-// A focusable view that performs an action when user clicks on it, or presses
-// enter or space when focused. Note that the action is triggered on mouse-up,
-// instead of on mouse-down. So if user presses the mouse on the view, then
-// moves the mouse out of the view and then releases, then the action will not
-// be performed.
-// Exported for SystemTray.
-class ASH_EXPORT ActionableView : public views::View {
- public:
- ActionableView();
-
- virtual ~ActionableView();
-
- // Set the accessible name.
- void SetAccessibleName(const string16& name);
- const string16& accessible_name() const { return accessible_name_; }
-
- protected:
- void DrawBorder(gfx::Canvas* canvas, const gfx::Rect& bounds);
-
- // Performs an action when user clicks on the view (on mouse-press event), or
- // presses a key when this view is in focus. Returns true if the event has
- // been handled and an action was performed. Returns false otherwise.
- virtual bool PerformAction(const ui::Event& event) = 0;
-
- // Overridden from views::View.
- virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
- virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnMouseCaptureLost() OVERRIDE;
- virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
- virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
-
- // Overridden from ui::EventHandler.
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
-
- private:
- string16 accessible_name_;
- bool has_capture_;
-
- DISALLOW_COPY_AND_ASSIGN(ActionableView);
-};
-
class ViewClickListener {
public:
virtual ~ViewClickListener() {}
virtual void ClickedOn(views::View* sender) = 0;
};
-// A view that changes background color on hover, and triggers a callback in the
-// associated ViewClickListener on click. The view can also be forced to
-// maintain a fixed height.
-class HoverHighlightView : public ActionableView {
- public:
- explicit HoverHighlightView(ViewClickListener* listener);
- virtual ~HoverHighlightView();
-
- // Convenience function for adding an icon and a label. This also sets the
- // accessible name.
- void AddIconAndLabel(const gfx::ImageSkia& image,
- const string16& text,
- gfx::Font::FontStyle style);
-
- // Convenience function for adding a label with padding on the left for a
- // blank icon. This also sets the accessible name.
- // Returns label after parenting it.
- views::Label* AddLabel(const string16& text, gfx::Font::FontStyle style);
-
- // Convenience function for adding an optional check and a label. In the
- // absence of a check, padding is added to align with checked items.
- // Returns label after parenting it.
- views::Label* AddCheckableLabel(const string16& text,
- gfx::Font::FontStyle style,
- bool checked);
-
- // Allows view to expand its height.
- // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
- void SetExpandable(bool expandable);
-
- void set_highlight_color(SkColor color) { highlight_color_ = color; }
- void set_default_color(SkColor color) { default_color_ = color; }
- void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; }
- void set_text_default_color(SkColor color) { text_default_color_ = color; }
-
- views::Label* text_label() {
- return text_label_;
- }
-
- bool hover() const { return hover_; }
-
- private:
- // Overridden from ActionableView.
- virtual bool PerformAction(const ui::Event& event) OVERRIDE;
-
- // Overridden from views::View.
- virtual gfx::Size GetPreferredSize() OVERRIDE;
- virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
- virtual void OnEnabledChanged() OVERRIDE;
- virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
- virtual void OnFocus() OVERRIDE;
-
- ViewClickListener* listener_;
- views::Label* text_label_;
- SkColor highlight_color_;
- SkColor default_color_;
- SkColor text_highlight_color_;
- SkColor text_default_color_;
- bool hover_;
- bool expandable_;
-
- DISALLOW_COPY_AND_ASSIGN(HoverHighlightView);
-};
-
// A custom scroll-view that has a specified dimension.
class FixedSizedScrollView : public views::ScrollView {
public:
diff --git a/ash/system/tray_accessibility.cc b/ash/system/tray_accessibility.cc
index 8703013..4e32652 100644
--- a/ash/system/tray_accessibility.cc
+++ b/ash/system/tray_accessibility.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/shell_delegate.h"
+#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
@@ -13,7 +14,6 @@
#include "ash/system/tray/tray_details_view.h"
#include "ash/system/tray/tray_item_more.h"
#include "ash/system/tray/tray_notification_view.h"
-#include "ash/system/tray/tray_views.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
diff --git a/ash/system/tray_accessibility.h b/ash/system/tray_accessibility.h
index bc374d2..a1a6f35 100644
--- a/ash/system/tray_accessibility.h
+++ b/ash/system/tray_accessibility.h
@@ -36,6 +36,9 @@ class ASH_EXPORT AccessibilityObserver {
};
namespace internal {
+
+class HoverHighlightView;
+
namespace tray {
class AccessibilityPopupView;
diff --git a/ash/system/tray_caps_lock.cc b/ash/system/tray_caps_lock.cc
index 9c0a7f1..89f2747 100644
--- a/ash/system/tray_caps_lock.cc
+++ b/ash/system/tray_caps_lock.cc
@@ -6,10 +6,10 @@
#include "ash/caps_lock_delegate.h"
#include "ash/shell.h"
+#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_views.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/accessibility/accessible_view_state.h"
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index bc06e9a..e044cdf 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -26,6 +26,7 @@
#include "ui/message_center/message_popup_bubble.h"
#include "ui/message_center/quiet_mode_bubble.h"
#include "ui/views/bubble/tray_bubble_view.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/widget/widget_observer.h"
#if defined(OS_CHROMEOS)
diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h
index 8a1a165..590e277 100644
--- a/ash/system/web_notification/web_notification_tray.h
+++ b/ash/system/web_notification/web_notification_tray.h
@@ -13,6 +13,7 @@
#include "ui/message_center/message_center_tray.h"
#include "ui/message_center/message_center_tray_delegate.h"
#include "ui/views/bubble/tray_bubble_view.h"
+#include "ui/views/controls/button/button.h"
#include "ui/views/widget/widget_observer.h"
// Status area tray for showing browser and app notifications. This hosts
@@ -23,6 +24,10 @@
// generated by SystemTrayItem). Visibility of one notification type or other
// is controlled by StatusAreaWidget.
+namespace views {
+class ImageButton;
+}
+
namespace message_center {
class MessageBubbleBase;
class MessageCenter;