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 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | 11 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
12 #include "ash/common/system/tray/fixed_sized_image_view.h" | |
13 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
13 #include "ash/common/system/tray/hover_highlight_view.h" | |
14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
15 #include "ash/common/system/tray/system_tray_notifier.h" | 15 #include "ash/common/system/tray/system_tray_notifier.h" |
16 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
17 #include "ash/common/system/tray/tray_popup_header_button.h" | 17 #include "ash/common/system/tray/tray_popup_header_button.h" |
18 #include "ash/common/system/tray/tray_utils.h" | 18 #include "ash/common/system/tray/tray_utils.h" |
19 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
20 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
21 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
22 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 TrayPopupHeaderButton* button = | 71 TrayPopupHeaderButton* button = |
72 new TrayPopupHeaderButton(listener, enabled_resource_id, | 72 new TrayPopupHeaderButton(listener, enabled_resource_id, |
73 disabled_resource_id, enabled_resource_id_hover, | 73 disabled_resource_id, enabled_resource_id_hover, |
74 disabled_resource_id_hover, accessible_name_id); | 74 disabled_resource_id_hover, accessible_name_id); |
75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); | 75 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); |
76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, | 76 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, |
77 kBorderDarkColor)); | 77 kBorderDarkColor)); |
78 return button; | 78 return button; |
79 } | 79 } |
80 | 80 |
81 // The IME menu settings view when there's only one button on the menu. It shows | 81 class ImeButtonsView : public views::View, |
James Cook
2016/08/29 16:12:02
nit: class comment please
Azure Wei
2016/08/29 23:59:56
Done.
| |
82 // the setting gear left-aligned with label. | 82 public views::ButtonListener, |
83 class ImeSettingButtonView : public ActionableView { | 83 public ViewClickListener { |
84 public: | |
85 ImeSettingButtonView() { | |
86 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | |
87 kTrayPopupPaddingHorizontal, 0, | |
88 kTrayPopupPaddingBetweenItems)); | |
89 | |
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
91 views::ImageView* icon = | |
92 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
93 icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | |
94 AddChildView(icon); | |
95 | |
96 base::string16 text = | |
97 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_INPUT_SETTINGS); | |
98 views::Label* label = new views::Label(text); | |
99 AddChildView(label); | |
100 SetAccessibleName(text); | |
101 } | |
102 | |
103 ~ImeSettingButtonView() override {} | |
104 | |
105 // ActionableView. | |
106 bool PerformAction(const ui::Event& event) override { | |
107 ShowIMESettings(); | |
108 return true; | |
109 } | |
110 | |
111 private: | |
112 DISALLOW_COPY_AND_ASSIGN(ImeSettingButtonView); | |
113 }; | |
114 | |
115 class ImeButtonsView : public views::View, public views::ButtonListener { | |
116 public: | 84 public: |
117 ImeButtonsView(bool show_emoji_button, | 85 ImeButtonsView(bool show_emoji_button, |
118 bool show_voice_button, | 86 bool show_voice_button, |
119 bool show_handwriting_button, | 87 bool show_handwriting_button, |
120 bool show_settings_button) { | 88 bool show_settings_button) { |
121 set_background( | |
122 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | |
123 SetBorder( | 89 SetBorder( |
124 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); | 90 views::Border::CreateSolidSidedBorder(1, 0, 0, 0, kBorderDarkColor)); |
125 | 91 |
126 auto* box_layout = new views::BoxLayout( | 92 // If there's only one settings button, the bottom should be a label with |
127 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, | 93 // normal background. Otherwise, show button icons with header background. |
128 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); | 94 if (show_settings_button && !show_emoji_button && !show_voice_button && |
129 box_layout->SetDefaultFlex(1); | 95 !show_handwriting_button) { |
130 SetLayoutManager(box_layout); | 96 ShowOneSettingButton(); |
131 | 97 } else { |
132 if (show_emoji_button) { | 98 ShowButtons(show_emoji_button, show_voice_button, show_handwriting_button, |
133 // TODO(azurewei): Creates the proper button with icons. | 99 show_settings_button); |
134 } | 100 } |
135 | 101 // TODO(azurewei): Add logic of switching between the two states when the |
136 if (show_voice_button) { | 102 // menu is shown. |
137 // TODO(azurewei): Creates the proper button with icons. | |
138 } | |
139 | |
140 if (show_handwriting_button) { | |
141 // TODO(azurewei): Creates the proper button with icons. | |
142 } | |
143 | |
144 if (show_settings_button) { | |
145 // If there's only one button, we show the gear icon with text. Otherwise, | |
146 // just show the icon. | |
147 if (!show_emoji_button && !show_voice_button && | |
148 !show_handwriting_button) { | |
149 settings_button_with_text_ = new ImeSettingButtonView(); | |
150 AddChildView(settings_button_with_text_); | |
151 } else { | |
152 settings_button_ = CreateImeMenuButton( | |
153 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | |
154 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | |
155 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); | |
156 AddChildView(settings_button_); | |
157 } | |
158 } | |
159 } | 103 } |
160 | 104 |
161 ~ImeButtonsView() override {} | 105 ~ImeButtonsView() override {} |
162 | 106 |
163 // views::View: | 107 // views::View: |
164 gfx::Size GetPreferredSize() const override { | 108 gfx::Size GetPreferredSize() const override { |
165 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); | 109 int size = GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); |
166 return gfx::Size(size, size); | 110 return gfx::Size(size, size); |
167 } | 111 } |
168 int GetHeightForWidth(int width) const override { | 112 int GetHeightForWidth(int width) const override { |
169 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); | 113 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT); |
170 } | 114 } |
171 | 115 |
172 // views::ButtonListener: | 116 // views::ButtonListener: |
173 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 117 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
174 if (emoji_button_ && sender == emoji_button_) { | 118 if (emoji_button_ && sender == emoji_button_) { |
175 // TODO(azurewei): Opens emoji palette. | 119 // TODO(azurewei): Opens emoji palette. |
176 } else if (voice_button_ && sender == voice_button_) { | 120 } else if (voice_button_ && sender == voice_button_) { |
177 // TODO(azurewei): Brings virtual keyboard for emoji input. | 121 // TODO(azurewei): Brings virtual keyboard for emoji input. |
178 } else if (handwriting_button_ && sender == handwriting_button_) { | 122 } else if (handwriting_button_ && sender == handwriting_button_) { |
179 // TODO(azurewei): Brings virtual keyboard for handwriting input. | 123 // TODO(azurewei): Brings virtual keyboard for handwriting input. |
180 } else if (settings_button_ && sender == settings_button_) { | 124 } else if (settings_button_ && sender == settings_button_) { |
181 ShowIMESettings(); | 125 ShowIMESettings(); |
182 } | 126 } |
183 } | 127 } |
184 | 128 |
129 // ViewClickListener: | |
130 void OnViewClicked(views::View* sender) override { | |
131 if (one_settings_button_view_ && sender == one_settings_button_view_) { | |
132 ShowIMESettings(); | |
133 } | |
134 } | |
135 | |
185 private: | 136 private: |
137 // Shows the UI of one settings button. | |
138 void ShowOneSettingButton() { | |
139 auto* box_layout = | |
140 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
141 box_layout->SetDefaultFlex(1); | |
142 SetLayoutManager(box_layout); | |
143 one_settings_button_view_ = new HoverHighlightView(this); | |
144 one_settings_button_view_->AddLabel( | |
145 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
146 IDS_ASH_STATUS_TRAY_IME_SETTINGS), | |
147 gfx::ALIGN_LEFT, false /* highlight */); | |
148 AddChildView(one_settings_button_view_); | |
149 } | |
150 | |
151 // Shows the UI of more than one buttons. | |
152 void ShowButtons(bool show_emoji_button, | |
153 bool show_voice_button, | |
154 bool show_handwriting_button, | |
155 bool show_settings_button) { | |
156 set_background( | |
157 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | |
158 auto* box_layout = new views::BoxLayout( | |
159 views::BoxLayout::kHorizontal, kTrayImeBottomRowPadding, | |
160 kTrayImeBottomRowPadding, kTrayImeBottomRowPaddingBetweenItems); | |
161 box_layout->SetDefaultFlex(1); | |
162 SetLayoutManager(box_layout); | |
163 | |
164 if (show_emoji_button) { | |
165 // TODO(azurewei): Creates the proper button with icons. | |
166 } | |
167 | |
168 if (show_voice_button) { | |
169 // TODO(azurewei): Creates the proper button with icons. | |
170 } | |
171 | |
172 if (show_handwriting_button) { | |
173 // TODO(azurewei): Creates the proper button with icons. | |
174 } | |
175 | |
176 if (show_settings_button) { | |
177 settings_button_ = CreateImeMenuButton( | |
178 this, IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | |
179 IDR_AURA_UBER_TRAY_SETTINGS, IDR_AURA_UBER_TRAY_SETTINGS, | |
180 IDS_ASH_STATUS_TRAY_SETTINGS, IDS_ASH_STATUS_TRAY_SETTINGS, 0); | |
181 AddChildView(settings_button_); | |
182 } | |
183 } | |
184 | |
186 TrayPopupHeaderButton* emoji_button_; | 185 TrayPopupHeaderButton* emoji_button_; |
187 TrayPopupHeaderButton* voice_button_; | 186 TrayPopupHeaderButton* voice_button_; |
188 TrayPopupHeaderButton* handwriting_button_; | 187 TrayPopupHeaderButton* handwriting_button_; |
189 TrayPopupHeaderButton* settings_button_; | 188 TrayPopupHeaderButton* settings_button_; |
190 ImeSettingButtonView* settings_button_with_text_; | 189 HoverHighlightView* one_settings_button_view_; |
191 | 190 |
192 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); | 191 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); |
193 }; | 192 }; |
194 | 193 |
195 } // namespace | 194 } // namespace |
196 | 195 |
197 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) | 196 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) |
198 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { | 197 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { |
199 SetupLabelForTray(label_); | 198 SetupLabelForTray(label_); |
200 tray_container()->AddChildView(label_); | 199 tray_container()->AddChildView(label_); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 label_->SetText(current_ime_.short_name); | 349 label_->SetText(current_ime_.short_name); |
351 } | 350 } |
352 | 351 |
353 void ImeMenuTray::HideImeMenuBubble() { | 352 void ImeMenuTray::HideImeMenuBubble() { |
354 bubble_.reset(); | 353 bubble_.reset(); |
355 ime_list_view_ = nullptr; | 354 ime_list_view_ = nullptr; |
356 SetDrawBackgroundAsActive(false); | 355 SetDrawBackgroundAsActive(false); |
357 } | 356 } |
358 | 357 |
359 } // namespace ash | 358 } // namespace ash |
OLD | NEW |