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

Side by Side Diff: chrome/browser/chromeos/status/status_area_view.cc

Issue 8438064: Separate StatusAreaView from StatusAreaViewChromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/status_area_view.h" 5 #include "chrome/browser/chromeos/status/status_area_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "chrome/browser/chromeos/status/accessibility_menu_button.h" 11 #include "chrome/browser/chromeos/status/accessibility_menu_button.h"
12 #include "chrome/browser/chromeos/status/caps_lock_menu_button.h" 12 #include "chrome/browser/chromeos/status/caps_lock_menu_button.h"
13 #include "chrome/browser/chromeos/status/clock_menu_button.h" 13 #include "chrome/browser/chromeos/status/clock_menu_button.h"
14 #include "chrome/browser/chromeos/status/input_method_menu_button.h" 14 #include "chrome/browser/chromeos/status/input_method_menu_button.h"
15 #include "chrome/browser/chromeos/status/memory_menu_button.h" 15 #include "chrome/browser/chromeos/status/memory_menu_button.h"
16 #include "chrome/browser/chromeos/status/network_menu_button.h" 16 #include "chrome/browser/chromeos/status/network_menu_button.h"
17 #include "chrome/browser/chromeos/status/power_menu_button.h" 17 #include "chrome/browser/chromeos/status/power_menu_button.h"
18 #include "chrome/browser/chromeos/status/status_area_host.h"
19 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
20 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
21 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
23 #include "views/border.h" 22 #include "views/border.h"
24 #include "views/controls/image_view.h" 23 #include "views/controls/image_view.h"
25 24
26 namespace chromeos {
27
28 // Number of pixels to separate each icon. 25 // Number of pixels to separate each icon.
29 #if defined(TOUCH_UI) 26 #if defined(TOUCH_UI)
30 const int kSeparation = 25; 27 const int kSeparation = 25;
31 #else 28 #else
32 const int kSeparation = 0; 29 const int kSeparation = 0;
33 #endif 30 #endif
34 31
35 StatusAreaView::StatusAreaView(StatusAreaHost* host) 32 StatusAreaView::StatusAreaView()
36 : host_(host), 33 : need_return_focus_(false) {
37 accessibility_view_(NULL),
38 caps_lock_view_(NULL),
39 clock_view_(NULL),
40 input_method_view_(NULL),
41 memory_view_(NULL),
42 network_view_(NULL),
43 power_view_(NULL),
44 need_return_focus_(false) {
45 } 34 }
46 35
47 StatusAreaView::~StatusAreaView() { 36 StatusAreaView::~StatusAreaView() {
48 } 37 }
49 38
50 void StatusAreaView::Init() { 39 void StatusAreaView::AddButton(StatusAreaButton* button, bool bordered) {
51 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget)) { 40 buttons_.push_back(button);
52 memory_view_ = new MemoryMenuButton(host_); 41 if (bordered)
53 AddChildView(memory_view_); 42 button->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0));
43 AddChildView(button);
44 UpdateButtonVisibility();
45 }
46
47 void StatusAreaView::RemoveButton(StatusAreaButton* button) {
48 std::list<StatusAreaButton*>::iterator iter =
49 std::find(buttons_.begin(), buttons_.end(), button);
50 if (iter != buttons_.end()) {
51 RemoveChildView(*iter);
52 buttons_.erase(iter);
54 } 53 }
54 UpdateButtonVisibility();
55 }
55 56
56 accessibility_view_ = new AccessibilityMenuButton(host_); 57 // views::View* overrides.
57 accessibility_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0));
58 AddChildView(accessibility_view_);
59
60 caps_lock_view_ = new CapsLockMenuButton(host_);
61 caps_lock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0));
62 AddChildView(caps_lock_view_);
63
64 clock_view_ = new ClockMenuButton(host_);
65 clock_view_->set_border(views::Border::CreateEmptyBorder(0, 1, 0, 0));
66 AddChildView(clock_view_);
67
68 input_method_view_ = new InputMethodMenuButton(host_);
69 AddChildView(input_method_view_);
70
71 network_view_ = new NetworkMenuButton(host_);
72 AddChildView(network_view_);
73
74 power_view_ = new PowerMenuButton(host_);
75 AddChildView(power_view_);
76 }
77 58
78 gfx::Size StatusAreaView::GetPreferredSize() { 59 gfx::Size StatusAreaView::GetPreferredSize() {
79 int result_w = 0; 60 int result_w = 0;
80 int result_h = 0; 61 int result_h = 0;
81 62
82 for (int i = 0; i < child_count(); i++) { 63 for (int i = 0; i < child_count(); i++) {
83 views::View* cur = child_at(i); 64 views::View* cur = child_at(i);
84 gfx::Size cur_size = cur->GetPreferredSize(); 65 gfx::Size cur_size = cur->GetPreferredSize();
85 if (cur->IsVisible() && !cur_size.IsEmpty()) { 66 if (cur->IsVisible() && !cur_size.IsEmpty()) {
86 if (result_w == 0) 67 if (result_w == 0)
(...skipping 28 matching lines...) Expand all
115 96
116 void StatusAreaView::ChildPreferredSizeChanged(View* child) { 97 void StatusAreaView::ChildPreferredSizeChanged(View* child) {
117 // When something like the clock menu button's size changes, we need to 98 // When something like the clock menu button's size changes, we need to
118 // relayout. Also mark that this view's size has changed. This will let 99 // relayout. Also mark that this view's size has changed. This will let
119 // BrowserView know to relayout, which will reset the bounds of this view. 100 // BrowserView know to relayout, which will reset the bounds of this view.
120 Layout(); 101 Layout();
121 PreferredSizeChanged(); 102 PreferredSizeChanged();
122 } 103 }
123 104
124 void StatusAreaView::MakeButtonsActive(bool active) { 105 void StatusAreaView::MakeButtonsActive(bool active) {
125 if (memory_view_) 106 for (std::list<StatusAreaButton*>::iterator iter = buttons_.begin();
126 memory_view_->set_active(active); 107 iter != buttons_.end(); ++iter) {
127 accessibility_view()->set_active(active); 108 (*iter)->set_menu_active(active);
128 caps_lock_view()->set_active(active); 109 }
129 clock_view()->set_active(active);
130 input_method_view()->set_active(active);
131 network_view()->set_active(active);
132 power_view()->set_active(active);
133 } 110 }
134 111
135 void StatusAreaView::ButtonVisibilityChanged(views::View* button_view) { 112 void StatusAreaView::UpdateButtonVisibility() {
136 Layout(); 113 Layout();
137 PreferredSizeChanged(); 114 PreferredSizeChanged();
138 } 115 }
139 116
140 void StatusAreaView::TakeFocus( 117 void StatusAreaView::TakeFocus(
141 bool reverse, 118 bool reverse,
142 const ReturnFocusCallback& return_focus_cb) { 119 const ReturnFocusCallback& return_focus_cb) {
143 // Emulates focus receive by AccessiblePaneView::SetPaneFocus. 120 // Emulates focus receive by AccessiblePaneView::SetPaneFocus.
144 if (!focus_manager_) 121 if (!focus_manager_)
145 focus_manager_ = GetFocusManager(); 122 focus_manager_ = GetFocusManager();
(...skipping 26 matching lines...) Expand all
172 const views::View* first = GetFirstFocusableChild(); 149 const views::View* first = GetFirstFocusableChild();
173 const views::View* last = GetLastFocusableChild(); 150 const views::View* last = GetLastFocusableChild();
174 const bool first_to_last = (focused_before == first && focused_now == last); 151 const bool first_to_last = (focused_before == first && focused_now == last);
175 const bool last_to_first = (focused_now == first && focused_before == last); 152 const bool last_to_first = (focused_now == first && focused_before == last);
176 153
177 if (first_to_last || last_to_first) 154 if (first_to_last || last_to_first)
178 MessageLoop::current()->PostTask(FROM_HERE, 155 MessageLoop::current()->PostTask(FROM_HERE,
179 base::Bind(&StatusAreaView::ReturnFocus, AsWeakPtr(), first_to_last)); 156 base::Bind(&StatusAreaView::ReturnFocus, AsWeakPtr(), first_to_last));
180 } 157 }
181 } 158 }
182
183 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/status_area_view.h ('k') | chrome/browser/chromeos/status/status_area_view_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698