| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/system/virtual_keyboard/virtual_keyboard_tray.h" | 5 #include "ash/system/virtual_keyboard/virtual_keyboard_tray.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/keyboard/keyboard_ui.h" | 9 #include "ash/keyboard/keyboard_ui.h" |
| 10 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
| 11 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 12 #include "ash/shelf/wm_shelf.h" | 12 #include "ash/shelf/wm_shelf.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/strings/grit/ash_strings.h" | 14 #include "ash/strings/grit/ash_strings.h" |
| 15 #include "ash/system/tray/tray_constants.h" | 15 #include "ash/system/tray/tray_constants.h" |
| 16 #include "ash/system/tray/tray_container.h" |
| 16 #include "ash/wm_window.h" | 17 #include "ash/wm_window.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 20 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 21 #include "ui/gfx/paint_vector_icon.h" | 22 #include "ui/gfx/paint_vector_icon.h" |
| 22 #include "ui/keyboard/keyboard_controller.h" | 23 #include "ui/keyboard/keyboard_controller.h" |
| 23 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| 26 | 27 |
| 27 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) | 28 VirtualKeyboardTray::VirtualKeyboardTray(WmShelf* wm_shelf) |
| 28 : TrayBackgroundView(wm_shelf, true), | 29 : TrayBackgroundView(wm_shelf), |
| 29 icon_(new views::ImageView), | 30 icon_(new views::ImageView), |
| 30 wm_shelf_(wm_shelf) { | 31 wm_shelf_(wm_shelf) { |
| 31 SetInkDropMode(InkDropMode::ON); | 32 SetInkDropMode(InkDropMode::ON); |
| 32 | 33 |
| 33 icon_->SetImage(gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor)); | 34 gfx::ImageSkia image = |
| 34 SetIconBorderForShelfAlignment(); | 35 gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor); |
| 36 icon_->SetImage(image); |
| 37 const int vertical_padding = (kTrayItemSize - image.height()) / 2; |
| 38 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; |
| 39 icon_->SetBorder(views::CreateEmptyBorder( |
| 40 gfx::Insets(vertical_padding, horizontal_padding))); |
| 35 tray_container()->AddChildView(icon_); | 41 tray_container()->AddChildView(icon_); |
| 36 | 42 |
| 37 // The Shell may not exist in some unit tests. | 43 // The Shell may not exist in some unit tests. |
| 38 if (Shell::HasInstance()) | 44 if (Shell::HasInstance()) |
| 39 Shell::Get()->keyboard_ui()->AddObserver(this); | 45 Shell::Get()->keyboard_ui()->AddObserver(this); |
| 40 // Try observing keyboard controller, in case it is already constructed. | 46 // Try observing keyboard controller, in case it is already constructed. |
| 41 ObserveKeyboardController(); | 47 ObserveKeyboardController(); |
| 42 } | 48 } |
| 43 | 49 |
| 44 VirtualKeyboardTray::~VirtualKeyboardTray() { | 50 VirtualKeyboardTray::~VirtualKeyboardTray() { |
| 45 // Try unobserving keyboard controller, in case it still exists. | 51 // Try unobserving keyboard controller, in case it still exists. |
| 46 UnobserveKeyboardController(); | 52 UnobserveKeyboardController(); |
| 47 // The Shell may not exist in some unit tests. | 53 // The Shell may not exist in some unit tests. |
| 48 if (Shell::HasInstance()) | 54 if (Shell::HasInstance()) |
| 49 Shell::Get()->keyboard_ui()->RemoveObserver(this); | 55 Shell::Get()->keyboard_ui()->RemoveObserver(this); |
| 50 } | 56 } |
| 51 | 57 |
| 52 void VirtualKeyboardTray::SetShelfAlignment(ShelfAlignment alignment) { | |
| 53 if (alignment == shelf_alignment()) | |
| 54 return; | |
| 55 | |
| 56 TrayBackgroundView::SetShelfAlignment(alignment); | |
| 57 SetIconBorderForShelfAlignment(); | |
| 58 } | |
| 59 | |
| 60 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { | 58 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { |
| 61 return l10n_util::GetStringUTF16( | 59 return l10n_util::GetStringUTF16( |
| 62 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); | 60 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); |
| 63 } | 61 } |
| 64 | 62 |
| 65 void VirtualKeyboardTray::HideBubbleWithView( | 63 void VirtualKeyboardTray::HideBubbleWithView( |
| 66 const views::TrayBubbleView* bubble_view) {} | 64 const views::TrayBubbleView* bubble_view) {} |
| 67 | 65 |
| 68 void VirtualKeyboardTray::ClickedOutsideBubble() {} | 66 void VirtualKeyboardTray::ClickedOutsideBubble() {} |
| 69 | 67 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 | 92 |
| 95 void VirtualKeyboardTray::OnKeyboardBoundsChanging( | 93 void VirtualKeyboardTray::OnKeyboardBoundsChanging( |
| 96 const gfx::Rect& new_bounds) { | 94 const gfx::Rect& new_bounds) { |
| 97 SetIsActive(!new_bounds.IsEmpty()); | 95 SetIsActive(!new_bounds.IsEmpty()); |
| 98 } | 96 } |
| 99 | 97 |
| 100 void VirtualKeyboardTray::OnKeyboardClosed() {} | 98 void VirtualKeyboardTray::OnKeyboardClosed() {} |
| 101 | 99 |
| 102 void VirtualKeyboardTray::SetIconBorderForShelfAlignment() { | |
| 103 const gfx::ImageSkia& image = icon_->GetImage(); | |
| 104 const int vertical_padding = (kTrayItemSize - image.height()) / 2; | |
| 105 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; | |
| 106 icon_->SetBorder(views::CreateEmptyBorder( | |
| 107 gfx::Insets(vertical_padding, horizontal_padding))); | |
| 108 } | |
| 109 | |
| 110 void VirtualKeyboardTray::ObserveKeyboardController() { | 100 void VirtualKeyboardTray::ObserveKeyboardController() { |
| 111 keyboard::KeyboardController* keyboard_controller = | 101 keyboard::KeyboardController* keyboard_controller = |
| 112 keyboard::KeyboardController::GetInstance(); | 102 keyboard::KeyboardController::GetInstance(); |
| 113 if (keyboard_controller) | 103 if (keyboard_controller) |
| 114 keyboard_controller->AddObserver(this); | 104 keyboard_controller->AddObserver(this); |
| 115 } | 105 } |
| 116 | 106 |
| 117 void VirtualKeyboardTray::UnobserveKeyboardController() { | 107 void VirtualKeyboardTray::UnobserveKeyboardController() { |
| 118 keyboard::KeyboardController* keyboard_controller = | 108 keyboard::KeyboardController* keyboard_controller = |
| 119 keyboard::KeyboardController::GetInstance(); | 109 keyboard::KeyboardController::GetInstance(); |
| 120 if (keyboard_controller) | 110 if (keyboard_controller) |
| 121 keyboard_controller->RemoveObserver(this); | 111 keyboard_controller->RemoveObserver(this); |
| 122 } | 112 } |
| 123 | 113 |
| 124 } // namespace ash | 114 } // namespace ash |
| OLD | NEW |