| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ | 5 #ifndef ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ |
| 6 #define ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ | 6 #define ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
| 10 #include "ui/gfx/size.h" | 10 #include "ui/gfx/size.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // A focusable view that performs an action when user clicks on it, or presses | 44 // A focusable view that performs an action when user clicks on it, or presses |
| 45 // enter or space when focused. | 45 // enter or space when focused. |
| 46 class ActionableView : public views::View { | 46 class ActionableView : public views::View { |
| 47 public: | 47 public: |
| 48 ActionableView(); | 48 ActionableView(); |
| 49 | 49 |
| 50 virtual ~ActionableView(); | 50 virtual ~ActionableView(); |
| 51 | 51 |
| 52 // Set the accessible name. |
| 53 void SetAccessibleName(const string16& name); |
| 54 const string16& accessible_name() const { return accessible_name_; } |
| 55 |
| 52 protected: | 56 protected: |
| 53 // Performs an action when user clicks on the view (on mouse-press event), or | 57 // Performs an action when user clicks on the view (on mouse-press event), or |
| 54 // presses a key when this view is in focus. Returns true if the event has | 58 // presses a key when this view is in focus. Returns true if the event has |
| 55 // been handled and an action was performed. Returns false otherwise. | 59 // been handled and an action was performed. Returns false otherwise. |
| 56 virtual bool PerformAction(const views::Event& event) = 0; | 60 virtual bool PerformAction(const views::Event& event) = 0; |
| 57 | 61 |
| 58 // Overridden from views::View. | 62 // Overridden from views::View. |
| 59 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | 63 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; |
| 60 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | 64 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
| 65 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 61 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; | 66 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; |
| 62 | 67 |
| 63 private: | 68 private: |
| 69 string16 accessible_name_; |
| 70 |
| 64 DISALLOW_COPY_AND_ASSIGN(ActionableView); | 71 DISALLOW_COPY_AND_ASSIGN(ActionableView); |
| 65 }; | 72 }; |
| 66 | 73 |
| 67 class ViewClickListener { | 74 class ViewClickListener { |
| 68 public: | 75 public: |
| 69 virtual ~ViewClickListener() {} | 76 virtual ~ViewClickListener() {} |
| 70 virtual void ClickedOn(views::View* sender) = 0; | 77 virtual void ClickedOn(views::View* sender) = 0; |
| 71 }; | 78 }; |
| 72 | 79 |
| 73 // A view that changes background color on hover, and triggers a callback in the | 80 // A view that changes background color on hover, and triggers a callback in the |
| 74 // associated ViewClickListener on click. The view can also be forced to | 81 // associated ViewClickListener on click. The view can also be forced to |
| 75 // maintain a fixed height. | 82 // maintain a fixed height. |
| 76 class HoverHighlightView : public ActionableView { | 83 class HoverHighlightView : public ActionableView { |
| 77 public: | 84 public: |
| 78 explicit HoverHighlightView(ViewClickListener* listener); | 85 explicit HoverHighlightView(ViewClickListener* listener); |
| 79 virtual ~HoverHighlightView(); | 86 virtual ~HoverHighlightView(); |
| 80 | 87 |
| 81 // Convenience function for adding an icon and a label. | 88 // Convenience function for adding an icon and a label. This also sets the |
| 89 // accessible name. |
| 82 void AddIconAndLabel(const SkBitmap& image, | 90 void AddIconAndLabel(const SkBitmap& image, |
| 83 const string16& text, | 91 const string16& text, |
| 84 gfx::Font::FontStyle style); | 92 gfx::Font::FontStyle style); |
| 85 | 93 |
| 86 // Convenience function for adding a label with padding on the left for a | 94 // Convenience function for adding a label with padding on the left for a |
| 87 // blank icon. | 95 // blank icon. This also sets the accessible name. |
| 88 void AddLabel(const string16& text, gfx::Font::FontStyle style); | 96 void AddLabel(const string16& text, gfx::Font::FontStyle style); |
| 89 | 97 |
| 90 // Set the accessible name. Should be used if this doesn't match the label. | |
| 91 void SetAccessibleName(const string16& name); | |
| 92 | |
| 93 void set_highlight_color(SkColor color) { highlight_color_ = color; } | 98 void set_highlight_color(SkColor color) { highlight_color_ = color; } |
| 94 void set_default_color(SkColor color) { default_color_ = color; } | 99 void set_default_color(SkColor color) { default_color_ = color; } |
| 95 void set_fixed_height(int height) { fixed_height_ = height; } | 100 void set_fixed_height(int height) { fixed_height_ = height; } |
| 96 | 101 |
| 97 private: | 102 private: |
| 98 // Overridden from ActionableView. | 103 // Overridden from ActionableView. |
| 99 virtual bool PerformAction(const views::Event& event) OVERRIDE; | 104 virtual bool PerformAction(const views::Event& event) OVERRIDE; |
| 100 | 105 |
| 101 // Overridden from views::View. | 106 // Overridden from views::View. |
| 102 virtual gfx::Size GetPreferredSize() OVERRIDE; | 107 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 103 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 108 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
| 104 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 109 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
| 105 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
| 106 virtual void OnEnabledChanged() OVERRIDE; | 110 virtual void OnEnabledChanged() OVERRIDE; |
| 107 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; | 111 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; |
| 108 | 112 |
| 109 ViewClickListener* listener_; | 113 ViewClickListener* listener_; |
| 110 string16 accessible_name_; | |
| 111 SkColor highlight_color_; | 114 SkColor highlight_color_; |
| 112 SkColor default_color_; | 115 SkColor default_color_; |
| 113 int fixed_height_; | 116 int fixed_height_; |
| 114 bool hover_; | 117 bool hover_; |
| 115 | 118 |
| 116 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); | 119 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); |
| 117 }; | 120 }; |
| 118 | 121 |
| 119 // A custom scroll-view that has a specified dimension. | 122 // A custom scroll-view that has a specified dimension. |
| 120 class FixedSizedScrollView : public views::ScrollView { | 123 class FixedSizedScrollView : public views::ScrollView { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 views::View* CreateDetailedHeaderEntry(int string_id, | 203 views::View* CreateDetailedHeaderEntry(int string_id, |
| 201 ViewClickListener* listener); | 204 ViewClickListener* listener); |
| 202 | 205 |
| 203 // Sets up a Label properly for the tray (sets color, font etc.). | 206 // Sets up a Label properly for the tray (sets color, font etc.). |
| 204 void SetupLabelForTray(views::Label* label); | 207 void SetupLabelForTray(views::Label* label); |
| 205 | 208 |
| 206 } // namespace internal | 209 } // namespace internal |
| 207 } // namespace ash | 210 } // namespace ash |
| 208 | 211 |
| 209 #endif // ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ | 212 #endif // ASH_SYSTEM_TRAY_TRAY_VIEWS_H_ |
| OLD | NEW |