Chromium Code Reviews| 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/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" | 10 #include "ash/common/system/chromeos/ime_menu/ime_list_view.h" |
| 11 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/system_tray_notifier.h" | 13 #include "ash/common/system/tray/system_tray_notifier.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/system/tray/tray_popup_header_button.h" | 15 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 15 #include "ash/common/system/tray/tray_utils.h" | 16 #include "ash/common/system/tray/tray_utils.h" |
| 16 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 17 #include "ash/common/wm_root_window_controller.h" | 18 #include "ash/common/wm_root_window_controller.h" |
| 18 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "grit/ash_resources.h" | 22 #include "grit/ash_resources.h" |
| 22 #include "grit/ash_strings.h" | 23 #include "grit/ash_strings.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
| 25 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
| 26 | 27 |
| 27 namespace ash { | 28 namespace ash { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 32 // Returns the max height of ImeListView. | |
| 33 int GetImeListViewMaxHeight() { | |
| 34 return GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT) * 7; | |
|
James Cook
2016/08/23 15:47:12
nit: Use a named constant for 7, like const int ma
| |
| 35 } | |
| 36 | |
| 31 class ImeMenuLabel : public views::Label { | 37 class ImeMenuLabel : public views::Label { |
| 32 public: | 38 public: |
| 33 ImeMenuLabel() {} | 39 ImeMenuLabel() {} |
| 34 ~ImeMenuLabel() override {} | 40 ~ImeMenuLabel() override {} |
| 35 | 41 |
| 36 // views:Label: | 42 // views:Label: |
| 37 gfx::Size GetPreferredSize() const override { | 43 gfx::Size GetPreferredSize() const override { |
| 38 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); | 44 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); |
| 39 } | 45 } |
| 40 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } | 46 int GetHeightForWidth(int width) const override { return kTrayImeIconSize; } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 kTrayPopupMinWidth, kTrayPopupMaxWidth); | 257 kTrayPopupMinWidth, kTrayPopupMaxWidth); |
| 252 init_params.first_item_has_no_margin = true; | 258 init_params.first_item_has_no_margin = true; |
| 253 init_params.can_activate = true; | 259 init_params.can_activate = true; |
| 254 init_params.close_on_deactivate = true; | 260 init_params.close_on_deactivate = true; |
| 255 | 261 |
| 256 views::TrayBubbleView* bubble_view = | 262 views::TrayBubbleView* bubble_view = |
| 257 views::TrayBubbleView::Create(tray_container(), this, &init_params); | 263 views::TrayBubbleView::Create(tray_container(), this, &init_params); |
| 258 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); | 264 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); |
| 259 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 265 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 260 | 266 |
| 267 ImeListView* ime_list_view = | |
| 268 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME); | |
| 269 if (ime_list_view->scroll_content()->height() > GetImeListViewMaxHeight()) { | |
| 270 ime_list_view->scroller()->SetFixedSize( | |
| 271 gfx::Size(kTrayPopupMaxWidth, GetImeListViewMaxHeight())); | |
| 272 } | |
| 261 // Adds IME list to the bubble. | 273 // Adds IME list to the bubble. |
| 262 bubble_view->AddChildView( | 274 bubble_view->AddChildView(ime_list_view); |
| 263 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME)); | |
| 264 | 275 |
| 265 // Adds IME buttons to the bubble if needed. | 276 // Adds IME buttons to the bubble if needed. |
| 266 LoginStatus login = | 277 LoginStatus login = |
| 267 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); | 278 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); |
| 268 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && | 279 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && |
| 269 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | 280 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) |
| 270 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); | 281 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); |
| 271 | 282 |
| 272 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | 283 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); |
| 273 SetDrawBackgroundAsActive(true); | 284 SetDrawBackgroundAsActive(true); |
| 274 } | 285 } |
| 275 | 286 |
| 276 void ImeMenuTray::HideImeMenuBubble() { | 287 void ImeMenuTray::HideImeMenuBubble() { |
| 277 bubble_.reset(); | 288 bubble_.reset(); |
| 278 SetDrawBackgroundAsActive(false); | 289 SetDrawBackgroundAsActive(false); |
| 279 } | 290 } |
| 280 | 291 |
| 281 } // namespace ash | 292 } // namespace ash |
| OLD | NEW |