| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ | 5 #ifndef ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ |
| 6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ | 6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ |
| 7 | 7 |
| 8 #include "ash/common/login_status.h" | 8 #include "ash/common/login_status.h" |
| 9 #include "ash/common/system/tray/tri_view.h" | 9 #include "ash/common/system/tray/tri_view.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 class Border; |
| 13 class ButtonListener; | 14 class ButtonListener; |
| 14 class ImageView; | 15 class ImageView; |
| 15 class Label; | 16 class Label; |
| 16 class LabelButton; | 17 class LabelButton; |
| 17 class LayoutManager; | 18 class LayoutManager; |
| 18 class Separator; | 19 class Separator; |
| 19 class Slider; | 20 class Slider; |
| 20 class SliderListener; | 21 class SliderListener; |
| 21 } // namespace views | 22 } // namespace views |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 | 25 |
| 25 // Factory/utility functions used by the system menu. | 26 // Factory/utility functions used by the system menu. |
| 26 class TrayPopupUtils { | 27 class TrayPopupUtils { |
| 27 public: | 28 public: |
| 28 // Creates a default container view to be used most system menu rows. The | 29 // Creates a default container view to be used by system menu rows that are |
| 29 // caller takes over ownership of the created view. | 30 // either a single targetable area or not targetable at all. The caller takes |
| 31 // over ownership of the created view. |
| 30 // | 32 // |
| 31 // The returned view consists of 3 regions: START, CENTER, and END. Any child | 33 // The returned view consists of 3 regions: START, CENTER, and END. Any child |
| 32 // Views added to the START and END containers will be added horizonatlly and | 34 // Views added to the START and END containers will be added horizontally and |
| 33 // any Views added to the CENTER container will be added vertically. | 35 // any Views added to the CENTER container will be added vertically. |
| 34 // | 36 // |
| 35 // The START and END containers have a fixed width but can grow into the | 37 // The START and END containers have a fixed minimum width but can grow into |
| 36 // CENTER container if space is required and available. | 38 // the CENTER container if space is required and available. |
| 37 // | 39 // |
| 38 // The CENTER container has a flexible width. | 40 // The CENTER container has a flexible width. |
| 39 static TriView* CreateDefaultRowView(); | 41 static TriView* CreateDefaultRowView(); |
| 40 | 42 |
| 41 // Creates the default layout manager by CreateDefault() row for the given | 43 // Creates a container view to be used by system menu rows that want to embed |
| 42 // |container|. To be used when mutliple targetable areas are required within | 44 // a targetable area within one (or more) of the containers OR by any row |
| 43 // a single row. | 45 // that requires a non-default layout within the container views. The returned |
| 44 static std::unique_ptr<views::LayoutManager> CreateLayoutManager( | 46 // view will have the following configurations: |
| 45 TriView::Container container); | 47 // - default minimum row height |
| 48 // - default minimum width for the START and END containers |
| 49 // - default left and right insets |
| 50 // - default container flex values |
| 51 // - Each container view will have a FillLayout installed on it |
| 52 // |
| 53 // The caller takes over ownership of the created view. |
| 54 // |
| 55 // The START and END containers have a fixed minimum width but can grow into |
| 56 // the CENTER container if space is required and available. The CENTER |
| 57 // container has a flexible width. |
| 58 // |
| 59 // Clients can use ConfigureContainer() to configure their own container views |
| 60 // before adding them to the returned TriView. |
| 61 static TriView* CreateMultiTargetRowView(); |
| 46 | 62 |
| 47 // Returns a label that has been configured for system menu layout. This | 63 // Returns a label that has been configured for system menu layout. This |
| 48 // should be used by all rows that require a label, i.e. both default and | 64 // should be used by all rows that require a label, i.e. both default and |
| 49 // detailed rows should use this. | 65 // detailed rows should use this. |
| 50 // | 66 // |
| 51 // TODO(bruthig): Update all system menu rows to use this. | 67 // TODO(bruthig): Update all system menu rows to use this. |
| 52 static views::Label* CreateDefaultLabel(); | 68 static views::Label* CreateDefaultLabel(); |
| 53 | 69 |
| 54 // Returns an image view to be used for the main image of a system menu row. | 70 // Returns an image view to be used in the main image region of a system menu |
| 55 // This should be used by all rows that have a main image, i.e. both default | 71 // row. This should be used by all rows that have a main image, i.e. both |
| 56 // and detailed rows should use this. | 72 // default and detailed rows should use this. |
| 57 // | 73 // |
| 58 // TODO(bruthig): Update all system menu rows to use this. | 74 // TODO(bruthig): Update all system menu rows to use this. |
| 59 static views::ImageView* CreateMainImageView(); | 75 static views::ImageView* CreateMainImageView(); |
| 60 | 76 |
| 61 // Returns an image view to be used for the 'more' arrow image on rows. In | 77 // Returns an image view to be used in the 'more' region of default rows. This |
| 62 // general this applies to all rows in the system menu that have a 'more' | 78 // is used for all 'more' images as well as other images that appear in this |
| 63 // image however most, if not all, are default rows. | 79 // region, e.g. audio output icon. |
| 64 // | 80 // |
| 65 // TODO(bruthig): Update all default rows to use this. | 81 // TODO(bruthig): Update all default rows to use this. |
| 66 static views::ImageView* CreateMoreImageView(); | 82 static views::ImageView* CreateMoreImageView(); |
| 67 | 83 |
| 84 // Returns a slider configured for proper layout within a TriView container |
| 85 // with a FillLayout. |
| 86 static views::Slider* CreateSlider(views::SliderListener* listener); |
| 87 |
| 88 // Configures |container_view| just like CreateDefaultRowView() would |
| 89 // configure |container| on its returned TriView. To be used when mutliple |
| 90 // targetable areas are required within a single row. |
| 91 static void ConfigureContainer(TriView::Container container, |
| 92 views::View* container_view); |
| 93 |
| 68 // Creates a button for use in the system menu that only has a visible border | 94 // Creates a button for use in the system menu that only has a visible border |
| 69 // when being hovered/clicked. Caller assumes ownership. | 95 // when being hovered/clicked. Caller assumes ownership. |
| 70 static views::LabelButton* CreateTrayPopupBorderlessButton( | 96 static views::LabelButton* CreateTrayPopupBorderlessButton( |
| 71 views::ButtonListener* listener, | 97 views::ButtonListener* listener, |
| 72 const base::string16& text); | 98 const base::string16& text); |
| 73 | 99 |
| 74 // Creates a button for use in the system menu. For MD, this is a prominent | 100 // Creates a button for use in the system menu. For MD, this is a prominent |
| 75 // text | 101 // text |
| 76 // button. For non-MD, this does the same thing as the above. Caller assumes | 102 // button. For non-MD, this does the same thing as the above. Caller assumes |
| 77 // ownership. | 103 // ownership. |
| 78 static views::LabelButton* CreateTrayPopupButton( | 104 static views::LabelButton* CreateTrayPopupButton( |
| 79 views::ButtonListener* listener, | 105 views::ButtonListener* listener, |
| 80 const base::string16& text); | 106 const base::string16& text); |
| 81 | 107 |
| 82 // Creates and returns a vertical separator to be used between two items in a | 108 // Creates and returns a vertical separator to be used between two items in a |
| 83 // material design system menu row. The caller assumes ownership of the | 109 // material design system menu row. The caller assumes ownership of the |
| 84 // returned separator. | 110 // returned separator. |
| 85 static views::Separator* CreateVerticalSeparator(); | 111 static views::Separator* CreateVerticalSeparator(); |
| 86 | 112 |
| 87 // Returns true if it is possible to open WebUI settings in a browser window, | 113 // Returns true if it is possible to open WebUI settings in a browser window, |
| 88 // i.e., the user is logged in, not on the lock screen, and not in a secondary | 114 // i.e., the user is logged in, not on the lock screen, and not in a secondary |
| 89 // account flow. | 115 // account flow. |
| 90 static bool CanOpenWebUISettings(LoginStatus status); | 116 static bool CanOpenWebUISettings(LoginStatus status); |
| 91 | 117 |
| 92 private: | 118 private: |
| 93 TrayPopupUtils() = delete; | 119 TrayPopupUtils() = delete; |
| 94 ~TrayPopupUtils() = delete; | 120 ~TrayPopupUtils() = delete; |
| 95 | 121 |
| 96 // Configures the specified |container| view with the default layout. Used by | 122 // Configures the default size and flex value for the specified |container| |
| 97 // CreateDefaultRowView(). | 123 // of the given |tri_view|. Used by CreateDefaultRowView(). |
| 98 static void ConfigureDefaultLayout(TriView* tri_view, | 124 static void ConfigureDefaultSizeAndFlex(TriView* tri_view, |
| 99 TriView::Container container); | 125 TriView::Container container); |
| 126 |
| 127 // Returns the default layout manager used by CreateDefaultRowView() and |
| 128 // ConfigureContainer() for the given |container|. |
| 129 static std::unique_ptr<views::LayoutManager> CreateDefaultLayoutManager( |
| 130 TriView::Container container); |
| 131 |
| 132 // Returns the default border used by CreateDefaultRow() and |
| 133 // ConfigureContainer() for the given |container|. |
| 134 static std::unique_ptr<views::Border> CreateDefaultBorder( |
| 135 TriView::Container container); |
| 100 }; | 136 }; |
| 101 | 137 |
| 102 } // namespace ash | 138 } // namespace ash |
| 103 | 139 |
| 104 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ | 140 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_UTILS_H_ |
| OLD | NEW |