Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_menu_tray.cc

Issue 2541743004: Set ImeListView's scrollable range when updating (Closed)
Patch Set: Add ImeMenuListView class. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 namespace { 49 namespace {
50 // Returns the height range of ImeListView. 50 // Returns the height range of ImeListView.
51 gfx::Range GetImeListViewRange() { 51 gfx::Range GetImeListViewRange() {
52 const int max_items = 5; 52 const int max_items = 5;
53 const int min_items = 2; 53 const int min_items = 2;
54 const int tray_item_height = GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT); 54 const int tray_item_height = GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT);
55 return gfx::Range(tray_item_height * min_items, tray_item_height * max_items); 55 return gfx::Range(tray_item_height * min_items, tray_item_height * max_items);
56 } 56 }
57 57
58 // Returns the minimum with of IME menu.
59 int GetMinimumMenuWidth() {
60 return MaterialDesignController::IsSystemTrayMenuMaterial()
61 ? kTrayMenuMinimumWidthMd
62 : kTrayMenuMinimumWidth;
63 }
64
58 // Shows language and input settings page. 65 // Shows language and input settings page.
59 void ShowIMESettings() { 66 void ShowIMESettings() {
60 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 67 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
61 WmShell::Get()->system_tray_controller()->ShowIMESettings(); 68 WmShell::Get()->system_tray_controller()->ShowIMESettings();
62 } 69 }
63 70
64 // Returns true if the current screen is login or lock screen. 71 // Returns true if the current screen is login or lock screen.
65 bool IsInLoginOrLockScreen() { 72 bool IsInLoginOrLockScreen() {
66 LoginStatus login = 73 LoginStatus login =
67 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); 74 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus();
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 ImeMenuTray* ime_menu_tray_; 293 ImeMenuTray* ime_menu_tray_;
287 SystemMenuButton* emoji_button_; 294 SystemMenuButton* emoji_button_;
288 SystemMenuButton* handwriting_button_; 295 SystemMenuButton* handwriting_button_;
289 SystemMenuButton* voice_button_; 296 SystemMenuButton* voice_button_;
290 SystemMenuButton* settings_button_; 297 SystemMenuButton* settings_button_;
291 HoverHighlightView* one_settings_button_view_; 298 HoverHighlightView* one_settings_button_view_;
292 299
293 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); 300 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView);
294 }; 301 };
295 302
303 // The list view that contains the selected IME and property items.
304 class ImeMenuListView : public ImeListView {
305 public:
306 explicit ImeMenuListView(SystemTrayItem* owner,
tdanderson 2016/12/07 22:53:04 nit: no 'explicit' since the constructor has more
Azure Wei 2016/12/08 03:04:12 Done. Removed 'explicit'.
307 bool show_keyboard_toggle,
308 SingleImeBehavior single_ime_behavior)
309 : ImeListView(owner, show_keyboard_toggle, ImeListView::HIDE_SINGLE_IME) {
310 }
311
312 ~ImeMenuListView() override {}
313
314 protected:
315 void Layout() override {
316 gfx::Range height_range = GetImeListViewRange();
317 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
318 scroller()->ClipHeightTo(height_range.start(), height_range.end());
319 } else {
320 uint32_t current_height = scroll_content()->height();
321 int minimum_menu_width = GetMinimumMenuWidth();
322 if (current_height > height_range.end()) {
323 scroller()->SetFixedSize(
324 gfx::Size(minimum_menu_width, height_range.end()));
325 } else if (current_height < height_range.start()) {
326 scroller()->SetFixedSize(
327 gfx::Size(minimum_menu_width, height_range.start()));
328 }
329 }
330 TrayDetailsView::Layout();
tdanderson 2016/12/07 22:53:04 I think this should instead call up to IMEListView
Azure Wei 2016/12/08 03:04:12 Yes, this should be ImeListView::Layout(). Thanks.
331 }
332
333 DISALLOW_COPY_AND_ASSIGN(ImeMenuListView);
334 };
335
296 } // namespace 336 } // namespace
297 337
298 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 338 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
299 : TrayBackgroundView(wm_shelf), 339 : TrayBackgroundView(wm_shelf),
300 label_(new ImeMenuLabel()), 340 label_(new ImeMenuLabel()),
301 show_keyboard_(false), 341 show_keyboard_(false),
302 force_show_keyboard_(false), 342 force_show_keyboard_(false),
303 should_block_shelf_auto_hide_(false), 343 should_block_shelf_auto_hide_(false),
304 keyboard_suppressed_(false) { 344 keyboard_suppressed_(false) {
305 if (MaterialDesignController::IsShelfMaterial()) { 345 if (MaterialDesignController::IsShelfMaterial()) {
(...skipping 11 matching lines...) Expand all
317 357
318 ImeMenuTray::~ImeMenuTray() { 358 ImeMenuTray::~ImeMenuTray() {
319 if (bubble_) 359 if (bubble_)
320 bubble_->bubble_view()->reset_delegate(); 360 bubble_->bubble_view()->reset_delegate();
321 SystemTrayNotifier* tray_notifier = WmShell::Get()->system_tray_notifier(); 361 SystemTrayNotifier* tray_notifier = WmShell::Get()->system_tray_notifier();
322 tray_notifier->RemoveIMEObserver(this); 362 tray_notifier->RemoveIMEObserver(this);
323 tray_notifier->RemoveVirtualKeyboardObserver(this); 363 tray_notifier->RemoveVirtualKeyboardObserver(this);
324 } 364 }
325 365
326 void ImeMenuTray::ShowImeMenuBubble() { 366 void ImeMenuTray::ShowImeMenuBubble() {
327 int minimum_menu_width = MaterialDesignController::IsSystemTrayMenuMaterial() 367 int minimum_menu_width = GetMinimumMenuWidth();
328 ? kTrayMenuMinimumWidthMd
329 : kTrayMenuMinimumWidth;
330 should_block_shelf_auto_hide_ = true; 368 should_block_shelf_auto_hide_ = true;
331 views::TrayBubbleView::InitParams init_params( 369 views::TrayBubbleView::InitParams init_params(
332 GetAnchorAlignment(), minimum_menu_width, minimum_menu_width); 370 GetAnchorAlignment(), minimum_menu_width, minimum_menu_width);
333 init_params.can_activate = true; 371 init_params.can_activate = true;
334 init_params.close_on_deactivate = true; 372 init_params.close_on_deactivate = true;
335 373
336 views::TrayBubbleView* bubble_view = 374 views::TrayBubbleView* bubble_view =
337 views::TrayBubbleView::Create(GetBubbleAnchor(), this, &init_params); 375 views::TrayBubbleView::Create(GetBubbleAnchor(), this, &init_params);
338 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); 376 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets());
339 377
340 // In the material design, we will add a title item with a separator on the 378 // In the material design, we will add a title item with a separator on the
341 // top of the IME menu. 379 // top of the IME menu.
342 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 380 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
343 bubble_view->AddChildView( 381 bubble_view->AddChildView(
344 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); 382 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons()));
345 } else { 383 } else {
346 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); 384 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0));
347 } 385 }
348 386
349 // Adds IME list to the bubble. 387 // Adds IME list to the bubble.
350 ime_list_view_ = new ImeListView(nullptr, ShouldShowKeyboardToggle(), 388 ime_list_view_ = new ImeMenuListView(nullptr, ShouldShowKeyboardToggle(),
351 ImeListView::SHOW_SINGLE_IME); 389 ImeListView::SHOW_SINGLE_IME);
352
353 uint32_t current_height = ime_list_view_->scroll_content()->height();
354 const gfx::Range height_range = GetImeListViewRange();
355
356 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
357 ime_list_view_->scroller()->ClipHeightTo(height_range.start(),
358 height_range.end());
359 } else if (current_height > height_range.end()) {
360 ime_list_view_->scroller()->SetFixedSize(
361 gfx::Size(minimum_menu_width, height_range.end()));
362 } else if (current_height < height_range.start()) {
363 ime_list_view_->scroller()->SetFixedSize(
364 gfx::Size(minimum_menu_width, height_range.start()));
365 }
366 bubble_view->AddChildView(ime_list_view_); 390 bubble_view->AddChildView(ime_list_view_);
367 391
368 // The bottom view that contains buttons are not supported in login/lock 392 // The bottom view that contains buttons are not supported in login/lock
369 // screen. 393 // screen.
370 if (!IsInLoginOrLockScreen()) { 394 if (!IsInLoginOrLockScreen()) {
371 if (ShouldShowEmojiHandwritingVoiceButtons()) { 395 if (ShouldShowEmojiHandwritingVoiceButtons()) {
372 bubble_view->AddChildView( 396 bubble_view->AddChildView(
373 new ImeButtonsView(this, true, true, true, true)); 397 new ImeButtonsView(this, true, true, true, true));
374 } else if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { 398 } else if (!MaterialDesignController::IsSystemTrayMenuMaterial()) {
375 // For MD, we don't need |ImeButtonsView| as the settings button will be 399 // For MD, we don't need |ImeButtonsView| as the settings button will be
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_); 586 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_);
563 587
564 // Updates the tray label based on the current input method. 588 // Updates the tray label based on the current input method.
565 if (current_ime_.third_party) 589 if (current_ime_.third_party)
566 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); 590 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*"));
567 else 591 else
568 label_->SetText(current_ime_.short_name); 592 label_->SetText(current_ime_.short_name);
569 } 593 }
570 594
571 } // namespace ash 595 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698