| 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/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
| 8 #include "ash/common/ash_constants.h" | 8 #include "ash/common/ash_constants.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 using chromeos::input_method::InputMethodManager; | 48 using chromeos::input_method::InputMethodManager; |
| 49 | 49 |
| 50 namespace ash { | 50 namespace ash { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 // Returns the height range of ImeListView. | 53 // Returns the height range of ImeListView. |
| 54 gfx::Range GetImeListViewRange() { | 54 gfx::Range GetImeListViewRange() { |
| 55 const int max_items = 5; | 55 const int max_items = 5; |
| 56 const int min_items = 1; | 56 const int min_items = 1; |
| 57 const int tray_item_height = GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT); | 57 const int tray_item_height = kTrayPopupItemMinHeight; |
| 58 return gfx::Range(tray_item_height * min_items, tray_item_height * max_items); | 58 return gfx::Range(tray_item_height * min_items, tray_item_height * max_items); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Returns the minimum with of IME menu. | 61 // Returns the minimum with of IME menu. |
| 62 int GetMinimumMenuWidth() { | 62 int GetMinimumMenuWidth() { |
| 63 return MaterialDesignController::IsSystemTrayMenuMaterial() | 63 return MaterialDesignController::IsSystemTrayMenuMaterial() |
| 64 ? kTrayMenuMinimumWidthMd | 64 ? kTrayMenuMinimumWidthMd |
| 65 : kTrayMenuMinimumWidth; | 65 : kTrayMenuMinimumWidth; |
| 66 } | 66 } |
| 67 | 67 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ui::TEXT_INPUT_TYPE_PASSWORD; | 106 ui::TEXT_INPUT_TYPE_PASSWORD; |
| 107 } | 107 } |
| 108 | 108 |
| 109 class ImeMenuLabel : public views::Label { | 109 class ImeMenuLabel : public views::Label { |
| 110 public: | 110 public: |
| 111 ImeMenuLabel() {} | 111 ImeMenuLabel() {} |
| 112 ~ImeMenuLabel() override {} | 112 ~ImeMenuLabel() override {} |
| 113 | 113 |
| 114 // views:Label: | 114 // views:Label: |
| 115 gfx::Size GetPreferredSize() const override { | 115 gfx::Size GetPreferredSize() const override { |
| 116 const int tray_constant = GetTrayConstant(TRAY_IME_MENU_ICON); | 116 return gfx::Size(kTrayItemSize, kTrayItemSize); |
| 117 return gfx::Size(tray_constant, tray_constant); | |
| 118 } | 117 } |
| 119 int GetHeightForWidth(int width) const override { | 118 int GetHeightForWidth(int width) const override { return kTrayItemSize; } |
| 120 return GetTrayConstant(TRAY_IME_MENU_ICON); | |
| 121 } | |
| 122 | 119 |
| 123 private: | 120 private: |
| 124 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); | 121 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); |
| 125 }; | 122 }; |
| 126 | 123 |
| 127 SystemMenuButton* CreateImeMenuButton(views::ButtonListener* listener, | 124 SystemMenuButton* CreateImeMenuButton(views::ButtonListener* listener, |
| 128 const gfx::VectorIcon& icon, | 125 const gfx::VectorIcon& icon, |
| 129 int accessible_name_id, | 126 int accessible_name_id, |
| 130 int right_border) { | 127 int right_border) { |
| 131 SystemMenuButton* button = new SystemMenuButton( | 128 SystemMenuButton* button = new SystemMenuButton( |
| 132 listener, TrayPopupInkDropStyle::HOST_CENTERED, icon, accessible_name_id); | 129 listener, TrayPopupInkDropStyle::HOST_CENTERED, icon, accessible_name_id); |
| 133 if (!MaterialDesignController::IsShelfMaterial()) { | 130 if (!MaterialDesignController::IsShelfMaterial()) { |
| 134 button->SetBorder( | 131 button->SetBorder( |
| 135 views::CreateSolidSidedBorder(0, 0, 0, right_border, kBorderDarkColor)); | 132 views::CreateSolidSidedBorder(0, 0, 0, right_border, kBorderDarkColor)); |
| 136 } | 133 } |
| 137 return button; | 134 return button; |
| 138 } | 135 } |
| 139 | 136 |
| 140 // The view that contains IME menu title in the material design. | 137 // The view that contains IME menu title in the material design. |
| 141 class ImeTitleView : public views::View, public views::ButtonListener { | 138 class ImeTitleView : public views::View, public views::ButtonListener { |
| 142 public: | 139 public: |
| 143 explicit ImeTitleView(bool show_settings_button) : settings_button_(nullptr) { | 140 explicit ImeTitleView(bool show_settings_button) : settings_button_(nullptr) { |
| 144 SetBorder(views::CreatePaddedBorder( | 141 SetBorder(views::CreatePaddedBorder( |
| 145 views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0, | 142 views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0, |
| 146 kMenuSeparatorColor), | 143 kMenuSeparatorColor), |
| 147 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, 0))); | 144 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, 0))); |
| 148 auto* box_layout = | 145 auto* box_layout = |
| 149 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 146 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 150 box_layout->set_minimum_cross_axis_size( | 147 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
| 151 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); | |
| 152 SetLayoutManager(box_layout); | 148 SetLayoutManager(box_layout); |
| 153 auto title_label = | 149 auto title_label = |
| 154 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME)); | 150 new views::Label(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME)); |
| 155 title_label->SetBorder( | 151 title_label->SetBorder( |
| 156 views::CreateEmptyBorder(0, kMenuEdgeEffectivePadding, 1, 0)); | 152 views::CreateEmptyBorder(0, kMenuEdgeEffectivePadding, 1, 0)); |
| 157 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 153 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 158 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::TITLE); | 154 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::TITLE); |
| 159 style.SetupLabel(title_label); | 155 style.SetupLabel(title_label); |
| 160 | 156 |
| 161 AddChildView(title_label); | 157 AddChildView(title_label); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 266 } |
| 271 | 267 |
| 272 // Shows the UI of more than one buttons. | 268 // Shows the UI of more than one buttons. |
| 273 void ShowButtons(bool show_emoji_button, | 269 void ShowButtons(bool show_emoji_button, |
| 274 bool show_handwriting_button, | 270 bool show_handwriting_button, |
| 275 bool show_voice_button, | 271 bool show_voice_button, |
| 276 bool show_settings_button) { | 272 bool show_settings_button) { |
| 277 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 273 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 278 auto* box_layout = | 274 auto* box_layout = |
| 279 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 275 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 280 box_layout->set_minimum_cross_axis_size( | 276 box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
| 281 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); | |
| 282 SetLayoutManager(box_layout); | 277 SetLayoutManager(box_layout); |
| 283 SetBorder(views::CreatePaddedBorder( | 278 SetBorder(views::CreatePaddedBorder( |
| 284 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, | 279 views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0, |
| 285 kMenuSeparatorColor), | 280 kMenuSeparatorColor), |
| 286 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, | 281 gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, |
| 287 GetTrayConstant(TRAY_POPUP_ITEM_LEFT_INSET)))); | 282 kMenuExtraMarginFromLeftEdge))); |
| 288 } else { | 283 } else { |
| 289 auto* box_layout = | 284 auto* box_layout = |
| 290 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 4, 0); | 285 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 4, 0); |
| 291 set_background( | 286 set_background( |
| 292 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | 287 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); |
| 293 box_layout->SetDefaultFlex(1); | 288 box_layout->SetDefaultFlex(1); |
| 294 SetLayoutManager(box_layout); | 289 SetLayoutManager(box_layout); |
| 295 } | 290 } |
| 296 | 291 |
| 297 const int right_border = 1; | 292 const int right_border = 1; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); | 643 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); |
| 649 | 644 |
| 650 // Updates the tray label based on the current input method. | 645 // Updates the tray label based on the current input method. |
| 651 if (current_ime_.third_party) | 646 if (current_ime_.third_party) |
| 652 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | 647 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); |
| 653 else | 648 else |
| 654 label_->SetText(current_ime_.short_name); | 649 label_->SetText(current_ime_.short_name); |
| 655 } | 650 } |
| 656 | 651 |
| 657 } // namespace ash | 652 } // namespace ash |
| OLD | NEW |