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

Side by Side Diff: ash/system/virtual_keyboard/virtual_keyboard_tray.cc

Issue 2916653002: Updated the VK Tray button to properly remove visual activated state. (Closed)
Patch Set: Reordered observer detaching. Created 3 years, 6 months 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 | « ash/system/virtual_keyboard/virtual_keyboard_tray.h ('k') | 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 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"
(...skipping 21 matching lines...) Expand all
32 gfx::ImageSkia image = 32 gfx::ImageSkia image =
33 gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor); 33 gfx::CreateVectorIcon(kShelfKeyboardIcon, kShelfIconColor);
34 icon_->SetImage(image); 34 icon_->SetImage(image);
35 const int vertical_padding = (kTrayItemSize - image.height()) / 2; 35 const int vertical_padding = (kTrayItemSize - image.height()) / 2;
36 const int horizontal_padding = (kTrayItemSize - image.width()) / 2; 36 const int horizontal_padding = (kTrayItemSize - image.width()) / 2;
37 icon_->SetBorder(views::CreateEmptyBorder( 37 icon_->SetBorder(views::CreateEmptyBorder(
38 gfx::Insets(vertical_padding, horizontal_padding))); 38 gfx::Insets(vertical_padding, horizontal_padding)));
39 tray_container()->AddChildView(icon_); 39 tray_container()->AddChildView(icon_);
40 40
41 // The Shell may not exist in some unit tests. 41 // The Shell may not exist in some unit tests.
42 if (Shell::HasInstance()) 42 if (Shell::HasInstance()) {
43 Shell::Get()->keyboard_ui()->AddObserver(this); 43 Shell::Get()->keyboard_ui()->AddObserver(this);
44 Shell::Get()->AddShellObserver(this);
45 }
44 // Try observing keyboard controller, in case it is already constructed. 46 // Try observing keyboard controller, in case it is already constructed.
45 ObserveKeyboardController(); 47 ObserveKeyboardController();
46 } 48 }
47 49
48 VirtualKeyboardTray::~VirtualKeyboardTray() { 50 VirtualKeyboardTray::~VirtualKeyboardTray() {
49 // Try unobserving keyboard controller, in case it still exists. 51 // Try unobserving keyboard controller, in case it still exists.
50 UnobserveKeyboardController(); 52 UnobserveKeyboardController();
51 // The Shell may not exist in some unit tests. 53 // The Shell may not exist in some unit tests.
52 if (Shell::HasInstance()) 54 if (Shell::HasInstance()) {
55 Shell::Get()->RemoveShellObserver(this);
53 Shell::Get()->keyboard_ui()->RemoveObserver(this); 56 Shell::Get()->keyboard_ui()->RemoveObserver(this);
57 }
54 } 58 }
55 59
56 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() { 60 base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
57 return l10n_util::GetStringUTF16( 61 return l10n_util::GetStringUTF16(
58 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME); 62 IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
59 } 63 }
60 64
61 void VirtualKeyboardTray::HideBubbleWithView( 65 void VirtualKeyboardTray::HideBubbleWithView(
62 const views::TrayBubbleView* bubble_view) {} 66 const views::TrayBubbleView* bubble_view) {}
63 67
(...skipping 25 matching lines...) Expand all
89 } 93 }
90 } 94 }
91 95
92 void VirtualKeyboardTray::OnKeyboardBoundsChanging( 96 void VirtualKeyboardTray::OnKeyboardBoundsChanging(
93 const gfx::Rect& new_bounds) { 97 const gfx::Rect& new_bounds) {
94 SetIsActive(!new_bounds.IsEmpty()); 98 SetIsActive(!new_bounds.IsEmpty());
95 } 99 }
96 100
97 void VirtualKeyboardTray::OnKeyboardClosed() {} 101 void VirtualKeyboardTray::OnKeyboardClosed() {}
98 102
103 void VirtualKeyboardTray::OnKeyboardControllerCreated() {
104 ObserveKeyboardController();
105 }
106
99 void VirtualKeyboardTray::ObserveKeyboardController() { 107 void VirtualKeyboardTray::ObserveKeyboardController() {
100 keyboard::KeyboardController* keyboard_controller = 108 keyboard::KeyboardController* keyboard_controller =
101 keyboard::KeyboardController::GetInstance(); 109 keyboard::KeyboardController::GetInstance();
102 if (keyboard_controller) 110 if (keyboard_controller && !keyboard_controller->HasObserver(this))
103 keyboard_controller->AddObserver(this); 111 keyboard_controller->AddObserver(this);
104 } 112 }
105 113
106 void VirtualKeyboardTray::UnobserveKeyboardController() { 114 void VirtualKeyboardTray::UnobserveKeyboardController() {
107 keyboard::KeyboardController* keyboard_controller = 115 keyboard::KeyboardController* keyboard_controller =
108 keyboard::KeyboardController::GetInstance(); 116 keyboard::KeyboardController::GetInstance();
109 if (keyboard_controller) 117 if (keyboard_controller)
110 keyboard_controller->RemoveObserver(this); 118 keyboard_controller->RemoveObserver(this);
111 } 119 }
112 120
113 } // namespace ash 121 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/virtual_keyboard/virtual_keyboard_tray.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698