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

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

Issue 449050: Implement "Language Switcher" for Chromium OS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/status_area_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_area_view.h" 5 #include "chrome/browser/chromeos/status_area_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/gfx/canvas.h" 9 #include "app/gfx/canvas.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/theme_provider.h" 11 #include "app/theme_provider.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "chrome/app/chrome_dll_resource.h" 13 #include "chrome/app/chrome_dll_resource.h"
14 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/browser_window.h" 15 #include "chrome/browser/browser_window.h"
16 #include "chrome/browser/chromeos/clock_menu_button.h" 16 #include "chrome/browser/chromeos/clock_menu_button.h"
17 #include "chrome/browser/chromeos/language_menu_button.h"
17 #include "chrome/browser/chromeos/network_menu_button.h" 18 #include "chrome/browser/chromeos/network_menu_button.h"
18 #include "chrome/browser/chromeos/power_menu_button.h" 19 #include "chrome/browser/chromeos/power_menu_button.h"
19 #include "chrome/browser/chromeos/status_area_button.h" 20 #include "chrome/browser/chromeos/status_area_button.h"
20 #if !defined(TOOLKIT_VIEWS) 21 #if !defined(TOOLKIT_VIEWS)
21 #include "chrome/browser/gtk/browser_window_gtk.h" 22 #include "chrome/browser/gtk/browser_window_gtk.h"
22 #else 23 #else
23 #include "chrome/browser/views/frame/browser_view.h" 24 #include "chrome/browser/views/frame/browser_view.h"
24 #endif 25 #endif
25 #include "chrome/browser/profile.h" 26 #include "chrome/browser/profile.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "chrome/common/pref_service.h" 28 #include "chrome/common/pref_service.h"
28 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
30 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
31 #include "views/controls/menu/menu.h" 32 #include "views/controls/menu/menu.h"
32 #include "views/controls/menu/menu_2.h" 33 #include "views/controls/menu/menu_2.h"
33 34
34 namespace chromeos { 35 namespace chromeos {
35 36
36 // Number of pixels to pad on the left border. 37 // Number of pixels to pad on the left border.
37 const int kLeftBorder = 1; 38 const int kLeftBorder = 1;
38 // Number of pixels to separate the clock from the next item on the right. 39 // Number of pixels to separate the clock from the next item on the right.
39 const int kClockSeparation = 4; 40 const int kClockSeparation = 4;
41 // Number of pixels to separate the language selector from the next item
42 // on the right.
43 const int kLanguageSeparation = 4;
40 44
41 // BrowserWindowGtk tiles its image with this offset 45 // BrowserWindowGtk tiles its image with this offset
42 const int kCustomFrameBackgroundVerticalOffset = 15; 46 const int kCustomFrameBackgroundVerticalOffset = 15;
43 47
44 class OptionsMenuModel : public menus::SimpleMenuModel, 48 class OptionsMenuModel : public menus::SimpleMenuModel,
45 public menus::SimpleMenuModel::Delegate { 49 public menus::SimpleMenuModel::Delegate {
46 public: 50 public:
47 // These extra command IDs must be unique when combined with the options, 51 // These extra command IDs must be unique when combined with the options,
48 // so we just pick up the numbering where that stops. 52 // so we just pick up the numbering where that stops.
49 enum OtherCommands { 53 enum OtherCommands {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 123
120 // Default to opening new tabs on the left. 124 // Default to opening new tabs on the left.
121 StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ = 125 StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ =
122 StatusAreaView::OPEN_TABS_ON_LEFT; 126 StatusAreaView::OPEN_TABS_ON_LEFT;
123 127
124 StatusAreaView::StatusAreaView(Browser* browser, 128 StatusAreaView::StatusAreaView(Browser* browser,
125 gfx::NativeWindow window) 129 gfx::NativeWindow window)
126 : browser_(browser), 130 : browser_(browser),
127 window_(window), 131 window_(window),
128 clock_view_(NULL), 132 clock_view_(NULL),
133 language_view_(NULL),
129 network_view_(NULL), 134 network_view_(NULL),
130 battery_view_(NULL), 135 battery_view_(NULL),
131 menu_view_(NULL) { 136 menu_view_(NULL) {
132 } 137 }
133 138
134 void StatusAreaView::Init() { 139 void StatusAreaView::Init() {
135 ThemeProvider* theme = browser_->profile()->GetThemeProvider(); 140 ThemeProvider* theme = browser_->profile()->GetThemeProvider();
136 141
142 // Language.
143 language_view_ = new LanguageMenuButton(browser_);
144 AddChildView(language_view_);
145
137 // Clock. 146 // Clock.
138 clock_view_ = new ClockMenuButton(browser_); 147 clock_view_ = new ClockMenuButton(browser_);
139 AddChildView(clock_view_); 148 AddChildView(clock_view_);
140 149
141 // Battery. 150 // Battery.
142 battery_view_ = new PowerMenuButton(); 151 battery_view_ = new PowerMenuButton();
143 AddChildView(battery_view_); 152 AddChildView(battery_view_);
144 153
145 // Network. 154 // Network.
146 network_view_ = new NetworkMenuButton(window_); 155 network_view_ = new NetworkMenuButton(window_);
(...skipping 10 matching lines...) Expand all
157 // We only turn on/off the menu for views because 166 // We only turn on/off the menu for views because
158 // gtk version will not hide the toolbar in compact 167 // gtk version will not hide the toolbar in compact
159 // navigation bar mode. 168 // navigation bar mode.
160 menu_view_->SetVisible( 169 menu_view_->SetVisible(
161 !browser_->window()->IsToolbarVisible()); 170 !browser_->window()->IsToolbarVisible());
162 #endif 171 #endif
163 } 172 }
164 173
165 gfx::Size StatusAreaView::GetPreferredSize() { 174 gfx::Size StatusAreaView::GetPreferredSize() {
166 // Start with padding. 175 // Start with padding.
167 int result_w = kLeftBorder + kClockSeparation; 176 int result_w = kLeftBorder + kClockSeparation + kLanguageSeparation;
168 int result_h = 0; 177 int result_h = 0;
169 for (int i = 0; i < GetChildViewCount(); i++) { 178 for (int i = 0; i < GetChildViewCount(); i++) {
170 views::View* cur = GetChildViewAt(i); 179 views::View* cur = GetChildViewAt(i);
171 if (cur->IsVisible()) { 180 if (cur->IsVisible()) {
172 gfx::Size cur_size = cur->GetPreferredSize(); 181 gfx::Size cur_size = cur->GetPreferredSize();
173 // Add each width. 182 // Add each width.
174 result_w += cur_size.width(); 183 result_w += cur_size.width();
175 // Use max height. 184 // Use max height.
176 result_h = std::max(result_h, cur_size.height()); 185 result_h = std::max(result_h, cur_size.height());
177 } 186 }
(...skipping 10 matching lines...) Expand all
188 int cur_y = (height() - cur_size.height()) / 2; 197 int cur_y = (height() - cur_size.height()) / 2;
189 198
190 // Handle odd number of pixels. 199 // Handle odd number of pixels.
191 cur_y += (height() - cur_size.height()) % 2; 200 cur_y += (height() - cur_size.height()) % 2;
192 201
193 // Put next in row horizontally, and center vertically. 202 // Put next in row horizontally, and center vertically.
194 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height()); 203 cur->SetBounds(cur_x, cur_y, cur_size.width(), cur_size.height());
195 204
196 cur_x += cur_size.width(); 205 cur_x += cur_size.width();
197 206
198 // Buttons have built in padding, but clock doesn't. 207 // Buttons have built in padding, but clock and language status don't.
199 if (cur == clock_view_) 208 if (cur == clock_view_)
200 cur_x += kClockSeparation; 209 cur_x += kClockSeparation;
210 else if (cur == language_view_)
211 cur_x += kLanguageSeparation;
201 } 212 }
202 } 213 }
203 } 214 }
204 215
205 void StatusAreaView::Paint(gfx::Canvas* canvas) { 216 void StatusAreaView::Paint(gfx::Canvas* canvas) {
206 ThemeProvider* theme = browser_->profile()->GetThemeProvider(); 217 ThemeProvider* theme = browser_->profile()->GetThemeProvider();
207 218
208 // Fill the background. 219 // Fill the background.
209 int image_name; 220 int image_name;
210 if (browser_->window()->IsActive()) { 221 if (browser_->window()->IsActive()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void StatusAreaView::ExecuteCommand(int command_id) { 309 void StatusAreaView::ExecuteCommand(int command_id) {
299 browser_->ExecuteCommand(command_id); 310 browser_->ExecuteCommand(command_id);
300 } 311 }
301 312
302 void StatusAreaView::RunMenu(views::View* source, const gfx::Point& pt) { 313 void StatusAreaView::RunMenu(views::View* source, const gfx::Point& pt) {
303 CreateAppMenu(); 314 CreateAppMenu();
304 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 315 app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
305 } 316 }
306 317
307 } // namespace chromeos 318 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status_area_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698