| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/frame/browser_view.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/chromeos/chromeos_version.h" | |
| 13 #include "base/command_line.h" | |
| 14 #include "chrome/app/chrome_command_ids.h" | |
| 15 #include "chrome/browser/chromeos/frame/layout_mode_button.h" | |
| 16 #include "chrome/browser/chromeos/frame/panel_browser_view.h" | |
| 17 #include "chrome/browser/chromeos/status/input_method_menu_button.h" | |
| 18 #include "chrome/browser/chromeos/status/network_menu_button.h" | |
| 19 #include "chrome/browser/chromeos/status/status_area_button.h" | |
| 20 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h" | |
| 21 #include "chrome/browser/themes/theme_service.h" | |
| 22 #include "chrome/browser/themes/theme_service_factory.h" | |
| 23 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 24 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 25 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | |
| 26 #include "chrome/browser/ui/views/tabs/tab.h" | |
| 27 #include "chrome/browser/ui/views/tabs/tab_strip.h" | |
| 28 #include "chrome/browser/ui/views/theme_background.h" | |
| 29 #include "chrome/browser/ui/views/toolbar_view.h" | |
| 30 #include "chrome/common/chrome_switches.h" | |
| 31 #include "grit/generated_resources.h" | |
| 32 #include "grit/theme_resources_standard.h" | |
| 33 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | |
| 34 #include "ui/base/hit_test.h" | |
| 35 #include "ui/base/l10n/l10n_util.h" | |
| 36 #include "ui/base/models/simple_menu_model.h" | |
| 37 #include "ui/base/theme_provider.h" | |
| 38 #include "ui/gfx/canvas.h" | |
| 39 #include "ui/gfx/screen.h" | |
| 40 #include "ui/views/controls/button/button.h" | |
| 41 #include "ui/views/controls/button/image_button.h" | |
| 42 #include "ui/views/controls/menu/menu_delegate.h" | |
| 43 #include "ui/views/controls/menu/menu_item_view.h" | |
| 44 #include "ui/views/controls/menu/menu_runner.h" | |
| 45 #include "ui/views/widget/root_view.h" | |
| 46 #include "ui/views/widget/widget.h" | |
| 47 | |
| 48 #if defined(TOOLKIT_USES_GTK) | |
| 49 #include "chrome/browser/chromeos/legacy_window_manager/wm_ipc.h" | |
| 50 #endif | |
| 51 | |
| 52 namespace { | |
| 53 | |
| 54 // Amount to tweak the position of the status area to get it to look right. | |
| 55 const int kStatusAreaVerticalAdjustment = -1; | |
| 56 | |
| 57 // GDK representation of the _CHROME_STATE X atom. | |
| 58 static GdkAtom g_chrome_state_gdk_atom = 0; | |
| 59 | |
| 60 // This MenuItemView delegate class forwards to the | |
| 61 // SimpleMenuModel::Delegate() implementation. | |
| 62 class SimpleMenuModelDelegateAdapter : public views::MenuDelegate { | |
| 63 public: | |
| 64 explicit SimpleMenuModelDelegateAdapter( | |
| 65 ui::SimpleMenuModel::Delegate* simple_menu_model_delegate); | |
| 66 | |
| 67 // views::MenuDelegate implementation. | |
| 68 virtual bool GetAccelerator(int id, | |
| 69 ui::Accelerator* accelerator) OVERRIDE; | |
| 70 virtual string16 GetLabel(int id) const OVERRIDE; | |
| 71 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
| 72 virtual bool IsItemChecked(int id) const OVERRIDE; | |
| 73 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 74 | |
| 75 private: | |
| 76 ui::SimpleMenuModel::Delegate* simple_menu_model_delegate_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(SimpleMenuModelDelegateAdapter); | |
| 79 }; | |
| 80 | |
| 81 // SimpleMenuModelDelegateAdapter: | |
| 82 SimpleMenuModelDelegateAdapter::SimpleMenuModelDelegateAdapter( | |
| 83 ui::SimpleMenuModel::Delegate* simple_menu_model_delegate) | |
| 84 : simple_menu_model_delegate_(simple_menu_model_delegate) { | |
| 85 } | |
| 86 | |
| 87 // SimpleMenuModelDelegateAdapter, views::MenuDelegate implementation. | |
| 88 | |
| 89 bool SimpleMenuModelDelegateAdapter::GetAccelerator( | |
| 90 int id, | |
| 91 ui::Accelerator* accelerator) { | |
| 92 return simple_menu_model_delegate_->GetAcceleratorForCommandId( | |
| 93 id, accelerator); | |
| 94 } | |
| 95 | |
| 96 string16 SimpleMenuModelDelegateAdapter::GetLabel(int id) const { | |
| 97 return simple_menu_model_delegate_->GetLabelForCommandId(id); | |
| 98 } | |
| 99 | |
| 100 bool SimpleMenuModelDelegateAdapter::IsCommandEnabled(int id) const { | |
| 101 return simple_menu_model_delegate_->IsCommandIdEnabled(id); | |
| 102 } | |
| 103 | |
| 104 bool SimpleMenuModelDelegateAdapter::IsItemChecked(int id) const { | |
| 105 return simple_menu_model_delegate_->IsCommandIdChecked(id); | |
| 106 } | |
| 107 | |
| 108 void SimpleMenuModelDelegateAdapter::ExecuteCommand(int id) { | |
| 109 simple_menu_model_delegate_->ExecuteCommand(id); | |
| 110 } | |
| 111 | |
| 112 } // namespace | |
| 113 | |
| 114 namespace chromeos { | |
| 115 | |
| 116 // LayoutManager for BrowserView, which lays out extra components such as | |
| 117 // the status views as follows: | |
| 118 // ____ __ __ | |
| 119 // / \ \ \ [StatusArea] [LayoutModeButton] | |
| 120 // | |
| 121 class BrowserViewLayout : public ::BrowserViewLayout { | |
| 122 public: | |
| 123 BrowserViewLayout() : ::BrowserViewLayout() {} | |
| 124 virtual ~BrowserViewLayout() {} | |
| 125 | |
| 126 ////////////////////////////////////////////////////////////////////////////// | |
| 127 // BrowserViewLayout overrides: | |
| 128 | |
| 129 void Installed(views::View* host) { | |
| 130 status_area_ = NULL; | |
| 131 layout_mode_button_ = NULL; | |
| 132 ::BrowserViewLayout::Installed(host); | |
| 133 } | |
| 134 | |
| 135 void ViewAdded(views::View* host, | |
| 136 views::View* view) { | |
| 137 ::BrowserViewLayout::ViewAdded(host, view); | |
| 138 switch (view->id()) { | |
| 139 case VIEW_ID_STATUS_AREA: | |
| 140 status_area_ = static_cast<chromeos::StatusAreaViewChromeos*>(view); | |
| 141 break; | |
| 142 case VIEW_ID_LAYOUT_MODE_BUTTON: | |
| 143 layout_mode_button_ = static_cast<chromeos::LayoutModeButton*>(view); | |
| 144 break; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 // In the normal and the compact navigation bar mode, ChromeOS | |
| 149 // lays out compact navigation buttons and status views in the title | |
| 150 // area. See Layout | |
| 151 virtual int LayoutTabStripRegion() OVERRIDE { | |
| 152 if (browser_view_->IsFullscreen() || !browser_view_->IsTabStripVisible()) { | |
| 153 if (status_area_) { | |
| 154 status_area_->SetVisible(false); | |
| 155 UpdateStatusAreaBoundsProperty(); | |
| 156 } | |
| 157 tabstrip_->SetVisible(false); | |
| 158 tabstrip_->SetBounds(0, 0, 0, 0); | |
| 159 layout_mode_button_->SetVisible(false); | |
| 160 layout_mode_button_->SetBounds(0, 0, 0, 0); | |
| 161 return 0; | |
| 162 } | |
| 163 | |
| 164 gfx::Rect tabstrip_bounds( | |
| 165 browser_view_->frame()->GetBoundsForTabStrip(tabstrip_)); | |
| 166 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); | |
| 167 views::View::ConvertPointToView(browser_view_->parent(), browser_view_, | |
| 168 &tabstrip_origin); | |
| 169 tabstrip_bounds.set_origin(tabstrip_origin); | |
| 170 return LayoutTitlebarComponents(tabstrip_bounds); | |
| 171 } | |
| 172 | |
| 173 virtual bool IsPositionInWindowCaption(const gfx::Point& point) OVERRIDE { | |
| 174 return ::BrowserViewLayout::IsPositionInWindowCaption(point) | |
| 175 && !IsPointInViewsInTitleArea(point); | |
| 176 } | |
| 177 | |
| 178 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE { | |
| 179 gfx::Point point_in_browser_view_coords(point); | |
| 180 views::View::ConvertPointToView( | |
| 181 browser_view_->parent(), browser_view_, | |
| 182 &point_in_browser_view_coords); | |
| 183 return IsPointInViewsInTitleArea(point_in_browser_view_coords) ? | |
| 184 HTCLIENT : ::BrowserViewLayout::NonClientHitTest(point); | |
| 185 } | |
| 186 | |
| 187 private: | |
| 188 chromeos::BrowserView* chromeos_browser_view() { | |
| 189 return static_cast<chromeos::BrowserView*>(browser_view_); | |
| 190 } | |
| 191 | |
| 192 // Tests if the point is on one of views that are within the | |
| 193 // considered title bar area of client view. | |
| 194 bool IsPointInViewsInTitleArea(const gfx::Point& point) | |
| 195 const { | |
| 196 if (status_area_) { | |
| 197 gfx::Point point_in_status_area_coords(point); | |
| 198 views::View::ConvertPointToView(browser_view_, status_area_, | |
| 199 &point_in_status_area_coords); | |
| 200 if (status_area_->HitTest(point_in_status_area_coords)) | |
| 201 return true; | |
| 202 } | |
| 203 gfx::Point point_in_layout_mode_button_coords(point); | |
| 204 views::View::ConvertPointToView(browser_view_, layout_mode_button_, | |
| 205 &point_in_layout_mode_button_coords); | |
| 206 if (layout_mode_button_->HitTest(point_in_layout_mode_button_coords)) | |
| 207 return true; | |
| 208 | |
| 209 return false; | |
| 210 } | |
| 211 | |
| 212 // Lays out tabstrip, status area, and layout mode button in the title bar | |
| 213 // area (given by |bounds|). | |
| 214 int LayoutTitlebarComponents(const gfx::Rect& bounds) { | |
| 215 if (bounds.IsEmpty()) | |
| 216 return 0; | |
| 217 | |
| 218 const bool show_layout_mode_button = | |
| 219 chromeos_browser_view()->should_show_layout_mode_button(); | |
| 220 | |
| 221 tabstrip_->SetVisible(true); | |
| 222 if (status_area_) { | |
| 223 status_area_->SetVisible( | |
| 224 !chromeos_browser_view()->has_hide_status_area_property()); | |
| 225 } | |
| 226 layout_mode_button_->SetVisible(show_layout_mode_button); | |
| 227 | |
| 228 const gfx::Size layout_mode_button_size = | |
| 229 layout_mode_button_->GetPreferredSize(); | |
| 230 layout_mode_button_->SetBounds( | |
| 231 bounds.right() - layout_mode_button_size.width(), | |
| 232 bounds.y(), | |
| 233 layout_mode_button_size.width(), | |
| 234 layout_mode_button_size.height()); | |
| 235 | |
| 236 if (status_area_) { | |
| 237 // Lay out status area after tab strip and before layout mode button (if | |
| 238 // shown). | |
| 239 gfx::Size status_size = status_area_->GetPreferredSize(); | |
| 240 const int status_right = | |
| 241 show_layout_mode_button ? | |
| 242 layout_mode_button_->bounds().x() : | |
| 243 bounds.right(); | |
| 244 status_area_->SetBounds( | |
| 245 status_right - status_size.width(), | |
| 246 bounds.y() + kStatusAreaVerticalAdjustment, | |
| 247 status_size.width(), | |
| 248 status_size.height()); | |
| 249 UpdateStatusAreaBoundsProperty(); | |
| 250 } | |
| 251 tabstrip_->SetBounds(bounds.x(), bounds.y(), | |
| 252 std::max(0, status_area_->bounds().x() - bounds.x()), | |
| 253 bounds.height()); | |
| 254 return bounds.bottom(); | |
| 255 } | |
| 256 | |
| 257 // Updates |status_area_bounds_for_property_| based on the current bounds and | |
| 258 // calls WmIpc::SetStatusBoundsProperty() if it changed. | |
| 259 void UpdateStatusAreaBoundsProperty() { | |
| 260 if (!status_area_) | |
| 261 return; | |
| 262 gfx::Rect current_bounds; | |
| 263 if (status_area_->visible()) { | |
| 264 gfx::Rect translated_bounds = | |
| 265 status_area_->parent()->ConvertRectToWidget(status_area_->bounds()); | |
| 266 // To avoid a dead zone across the top of the screen, | |
| 267 // StatusAreaButton::HitTest() accepts clicks in the area between the top | |
| 268 // of its own bounds and the top of its parent view. Make the bounds that | |
| 269 // we report match. | |
| 270 current_bounds.SetRect( | |
| 271 translated_bounds.x(), | |
| 272 translated_bounds.y() - status_area_->bounds().y(), | |
| 273 translated_bounds.width(), | |
| 274 translated_bounds.height() + status_area_->bounds().y()); | |
| 275 } | |
| 276 | |
| 277 if (status_area_bounds_for_property_ != current_bounds) { | |
| 278 status_area_bounds_for_property_ = current_bounds; | |
| 279 #if defined(TOOLKIT_USES_GTK) | |
| 280 WmIpc::instance()->SetStatusBoundsProperty( | |
| 281 GTK_WIDGET(chromeos_browser_view()->frame()->GetNativeWindow()), | |
| 282 status_area_bounds_for_property_); | |
| 283 #endif | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 chromeos::StatusAreaViewChromeos* status_area_; | |
| 288 chromeos::LayoutModeButton* layout_mode_button_; | |
| 289 | |
| 290 // Most-recently-set bounds for the _CHROME_STATUS_BOUNDS property. | |
| 291 // Empty if |status_area_| isn't visible. Tracked here so we don't update the | |
| 292 // property needlessly on no-op relayouts. | |
| 293 gfx::Rect status_area_bounds_for_property_; | |
| 294 | |
| 295 DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout); | |
| 296 }; | |
| 297 | |
| 298 // BrowserView | |
| 299 | |
| 300 BrowserView::BrowserView(Browser* browser) | |
| 301 : ::BrowserView(browser), | |
| 302 status_area_(NULL), | |
| 303 layout_mode_button_(NULL), | |
| 304 saved_focused_widget_(NULL), | |
| 305 has_hide_status_area_property_(false), | |
| 306 should_show_layout_mode_button_(false) { | |
| 307 system_menu_delegate_.reset(new SimpleMenuModelDelegateAdapter(this)); | |
| 308 BrowserList::AddObserver(this); | |
| 309 MessageLoopForUI::current()->AddObserver(this); | |
| 310 | |
| 311 #if defined(TOOLKIT_USES_GTK) | |
| 312 if (!g_chrome_state_gdk_atom) | |
| 313 g_chrome_state_gdk_atom = | |
| 314 gdk_atom_intern( | |
| 315 WmIpc::instance()->GetAtomName(WmIpc::ATOM_CHROME_STATE).c_str(), | |
| 316 FALSE); // !only_if_exists | |
| 317 #endif | |
| 318 } | |
| 319 | |
| 320 BrowserView::~BrowserView() { | |
| 321 if (toolbar()) | |
| 322 toolbar()->RemoveMenuListener(this); | |
| 323 MessageLoopForUI::current()->RemoveObserver(this); | |
| 324 BrowserList::RemoveObserver(this); | |
| 325 } | |
| 326 | |
| 327 void BrowserView::AddTrayButton(StatusAreaButton* button, | |
| 328 StatusAreaView::ButtonBorder border) { | |
| 329 status_area_->AddButton(button, border); | |
| 330 } | |
| 331 | |
| 332 void BrowserView::RemoveTrayButton(StatusAreaButton* button) { | |
| 333 status_area_->RemoveButton(button); | |
| 334 } | |
| 335 | |
| 336 bool BrowserView::ContainsButton(StatusAreaButton* button) { | |
| 337 return status_area_->Contains(button); | |
| 338 } | |
| 339 | |
| 340 chromeos::BrowserView* BrowserView::GetBrowserViewForBrowser(Browser* browser) { | |
| 341 // This calls the static method BrowserView::GetBrowserViewForBrowser in the | |
| 342 // global namespace. Check the chrome/browser/ui/views/frame/browser_view.h | |
| 343 // file for details. | |
| 344 return static_cast<chromeos::BrowserView*>( | |
| 345 ::BrowserView::GetBrowserViewForBrowser(browser)); | |
| 346 } | |
| 347 | |
| 348 // BrowserView, ::BrowserView overrides: | |
| 349 | |
| 350 void BrowserView::Init() { | |
| 351 ::BrowserView::Init(); | |
| 352 StatusAreaViewChromeos::SetScreenMode(StatusAreaViewChromeos::BROWSER_MODE); | |
| 353 status_area_ = new StatusAreaViewChromeos(); | |
| 354 status_area_->Init(this); | |
| 355 AddChildView(status_area_); | |
| 356 | |
| 357 layout_mode_button_ = new LayoutModeButton(); | |
| 358 AddChildView(layout_mode_button_); | |
| 359 layout_mode_button_->Init(); | |
| 360 | |
| 361 frame()->non_client_view()->set_context_menu_controller(this); | |
| 362 | |
| 363 // Listen to wrench menu opens. | |
| 364 if (toolbar()) | |
| 365 toolbar()->AddMenuListener(this); | |
| 366 | |
| 367 // Listen for PropertyChange events (which we receive in DidProcessEvent()). | |
| 368 gtk_widget_add_events(GTK_WIDGET(frame()->GetNativeWindow()), | |
| 369 GDK_PROPERTY_CHANGE_MASK); | |
| 370 FetchHideStatusAreaProperty(); | |
| 371 UpdateLayoutModeButtonVisibility(); | |
| 372 | |
| 373 // Make sure the window is set to the right type. | |
| 374 std::vector<int> params; | |
| 375 params.push_back(browser()->tab_count()); | |
| 376 params.push_back(browser()->active_index()); | |
| 377 params.push_back(gtk_get_current_event_time()); | |
| 378 #if defined(TOOLKIT_USES_GTK) | |
| 379 WmIpc::instance()->SetWindowType( | |
| 380 GTK_WIDGET(frame()->GetNativeWindow()), | |
| 381 WM_IPC_WINDOW_CHROME_TOPLEVEL, | |
| 382 ¶ms); | |
| 383 #endif | |
| 384 } | |
| 385 | |
| 386 void BrowserView::Show() { | |
| 387 ShowInternal(true); | |
| 388 } | |
| 389 | |
| 390 void BrowserView::ShowInactive() { | |
| 391 ShowInternal(false); | |
| 392 } | |
| 393 | |
| 394 void BrowserView::ShowInternal(bool is_active) { | |
| 395 bool was_visible = frame()->IsVisible(); | |
| 396 if (is_active) | |
| 397 ::BrowserView::Show(); | |
| 398 else | |
| 399 ::BrowserView::ShowInactive(); | |
| 400 if (!was_visible) { | |
| 401 // Have to update the tab count and selected index to reflect reality. | |
| 402 std::vector<int> params; | |
| 403 params.push_back(browser()->tab_count()); | |
| 404 params.push_back(browser()->active_index()); | |
| 405 #if defined(TOOLKIT_USES_GTK) | |
| 406 WmIpc::instance()->SetWindowType( | |
| 407 GTK_WIDGET(frame()->GetNativeWindow()), | |
| 408 WM_IPC_WINDOW_CHROME_TOPLEVEL, | |
| 409 ¶ms); | |
| 410 #endif | |
| 411 } | |
| 412 } | |
| 413 | |
| 414 void BrowserView::FocusChromeOSStatus() { | |
| 415 if (status_area_) | |
| 416 status_area_->SetPaneFocus(NULL); | |
| 417 } | |
| 418 | |
| 419 views::LayoutManager* BrowserView::CreateLayoutManager() const { | |
| 420 return new BrowserViewLayout(); | |
| 421 } | |
| 422 | |
| 423 void BrowserView::ChildPreferredSizeChanged(View* child) { | |
| 424 Layout(); | |
| 425 } | |
| 426 | |
| 427 bool BrowserView::GetSavedWindowPlacement( | |
| 428 gfx::Rect* bounds, | |
| 429 ui::WindowShowState* show_state) const { | |
| 430 if (base::chromeos::IsRunningOnChromeOS() || | |
| 431 CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) { | |
| 432 // Typically we don't request a full screen size. This means we'll request a | |
| 433 // non-full screen size, layout/paint at that size, then the window manager | |
| 434 // will snap us to full screen size. This results in an ugly | |
| 435 // resize/paint. To avoid this we always request a full screen size. | |
| 436 *bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | |
| 437 *show_state = ui::SHOW_STATE_NORMAL; | |
| 438 return true; | |
| 439 } | |
| 440 return ::BrowserView::GetSavedWindowPlacement(bounds, show_state); | |
| 441 } | |
| 442 | |
| 443 void BrowserView::Cut() { | |
| 444 gtk_util::DoCut(this); | |
| 445 } | |
| 446 | |
| 447 void BrowserView::Copy() { | |
| 448 gtk_util::DoCopy(this); | |
| 449 } | |
| 450 | |
| 451 void BrowserView::Paste() { | |
| 452 gtk_util::DoPaste(this); | |
| 453 } | |
| 454 | |
| 455 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( | |
| 456 const gfx::Rect& bounds) { | |
| 457 GdkScreen* screen = gdk_screen_get_default(); | |
| 458 int width = gdk_screen_get_width(screen); | |
| 459 int height = gdk_screen_get_height(screen); | |
| 460 return browser::DispositionForPopupBounds(bounds, width, height); | |
| 461 } | |
| 462 | |
| 463 // views::ContextMenuController implementation. | |
| 464 void BrowserView::ShowContextMenuForView(views::View* source, | |
| 465 const gfx::Point& point) { | |
| 466 // Only show context menu if point is in unobscured parts of browser, i.e. | |
| 467 // if NonClientHitTest returns : | |
| 468 // - HTCAPTION: in title bar or unobscured part of tabstrip | |
| 469 // - HTNOWHERE: as the name implies. | |
| 470 gfx::Point point_in_parent_coords(point); | |
| 471 views::View::ConvertPointToView(NULL, parent(), &point_in_parent_coords); | |
| 472 int hit_test = NonClientHitTest(point_in_parent_coords); | |
| 473 if (hit_test == HTCAPTION || hit_test == HTNOWHERE) { | |
| 474 // rebuild menu so it reflects current application state | |
| 475 InitSystemMenu(); | |
| 476 if (system_menu_runner_->RunMenuAt(source->GetWidget(), NULL, | |
| 477 gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPLEFT, | |
| 478 views::MenuRunner::HAS_MNEMONICS) == | |
| 479 views::MenuRunner::MENU_DELETED) | |
| 480 return; | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 // BrowserView, views::MenuListener implementation. | |
| 485 void BrowserView::OnMenuOpened() { | |
| 486 // Save the focused widget before wrench menu opens. | |
| 487 saved_focused_widget_ = gtk_window_get_focus(GetNativeHandle()); | |
| 488 } | |
| 489 | |
| 490 // BrowserView, BrowserList::Observer implementation. | |
| 491 | |
| 492 void BrowserView::OnBrowserAdded(const Browser* browser) { | |
| 493 const bool was_showing = should_show_layout_mode_button_; | |
| 494 UpdateLayoutModeButtonVisibility(); | |
| 495 if (should_show_layout_mode_button_ != was_showing) | |
| 496 Layout(); | |
| 497 } | |
| 498 | |
| 499 void BrowserView::OnBrowserRemoved(const Browser* browser) { | |
| 500 const bool was_showing = should_show_layout_mode_button_; | |
| 501 UpdateLayoutModeButtonVisibility(); | |
| 502 if (should_show_layout_mode_button_ != was_showing) | |
| 503 Layout(); | |
| 504 } | |
| 505 | |
| 506 // StatusAreaButton::Delegate overrides. | |
| 507 | |
| 508 bool BrowserView::ShouldExecuteStatusAreaCommand( | |
| 509 const views::View* button_view, int command_id) const { | |
| 510 return true; | |
| 511 } | |
| 512 | |
| 513 void BrowserView::ExecuteStatusAreaCommand( | |
| 514 const views::View* button_view, int command_id) { | |
| 515 switch (command_id) { | |
| 516 case StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS: | |
| 517 browser()->OpenInternetOptionsDialog(); | |
| 518 break; | |
| 519 case StatusAreaButton::Delegate::SHOW_LANGUAGE_OPTIONS: | |
| 520 browser()->OpenLanguageOptionsDialog(); | |
| 521 break; | |
| 522 case StatusAreaButton::Delegate::SHOW_ADVANCED_OPTIONS: | |
| 523 browser()->OpenAdvancedOptionsDialog(); | |
| 524 break; | |
| 525 default: | |
| 526 NOTREACHED(); | |
| 527 } | |
| 528 } | |
| 529 | |
| 530 StatusAreaButton::TextStyle BrowserView::GetStatusAreaTextStyle() const { | |
| 531 ThemeService* theme_service = | |
| 532 ThemeServiceFactory::GetForProfile(browser()->profile()); | |
| 533 | |
| 534 if (!theme_service->UsingDefaultTheme()) | |
| 535 return StatusAreaButton::WHITE_HALOED_BOLD; | |
| 536 | |
| 537 return IsOffTheRecord() ? | |
| 538 StatusAreaButton::WHITE_PLAIN_BOLD : StatusAreaButton::GRAY_EMBOSSED_BOLD; | |
| 539 } | |
| 540 | |
| 541 void BrowserView::ButtonVisibilityChanged(views::View* button_view) { | |
| 542 if (status_area_) | |
| 543 status_area_->UpdateButtonVisibility(); | |
| 544 } | |
| 545 | |
| 546 // BrowserView, MessageLoopForUI::Observer implementation. | |
| 547 | |
| 548 #if defined(USE_AURA) | |
| 549 base::EventStatus BrowserView::WillProcessEvent( | |
| 550 const base::NativeEvent& event) OVERRIDE { | |
| 551 return base::EVENT_CONTINUE; | |
| 552 } | |
| 553 | |
| 554 void BrowserView::DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | |
| 555 // TODO(oshima): On Aura, WM should notify chrome someshow. | |
| 556 } | |
| 557 #else | |
| 558 void BrowserView::DidProcessEvent(GdkEvent* event) { | |
| 559 if (event->type == GDK_PROPERTY_NOTIFY) { | |
| 560 if (!frame()->GetNativeWindow()) | |
| 561 return; | |
| 562 | |
| 563 GdkEventProperty* property_event = | |
| 564 reinterpret_cast<GdkEventProperty*>(event); | |
| 565 if (property_event->window == | |
| 566 GTK_WIDGET(frame()->GetNativeWindow())->window) { | |
| 567 if (property_event->atom == g_chrome_state_gdk_atom) { | |
| 568 const bool had_property = has_hide_status_area_property_; | |
| 569 FetchHideStatusAreaProperty(); | |
| 570 if (has_hide_status_area_property_ != had_property) | |
| 571 Layout(); | |
| 572 } | |
| 573 } | |
| 574 } | |
| 575 } | |
| 576 #endif | |
| 577 | |
| 578 // BrowserView protected: | |
| 579 | |
| 580 void BrowserView::GetAccessiblePanes( | |
| 581 std::vector<views::AccessiblePaneView*>* panes) { | |
| 582 ::BrowserView::GetAccessiblePanes(panes); | |
| 583 if (status_area_) | |
| 584 panes->push_back(status_area_); | |
| 585 } | |
| 586 | |
| 587 // BrowserView private. | |
| 588 | |
| 589 void BrowserView::InitSystemMenu() { | |
| 590 views::MenuItemView* menu = | |
| 591 new views::MenuItemView(system_menu_delegate_.get()); | |
| 592 // MenuRunner takes ownership of menu. | |
| 593 system_menu_runner_.reset(new views::MenuRunner(menu)); | |
| 594 menu->AppendDelegateMenuItem(IDC_RESTORE_TAB); | |
| 595 menu->AppendMenuItemWithLabel(IDC_NEW_TAB, | |
| 596 l10n_util::GetStringUTF16(IDS_NEW_TAB)); | |
| 597 menu->AppendSeparator(); | |
| 598 menu->AppendMenuItemWithLabel(IDC_TASK_MANAGER, | |
| 599 l10n_util::GetStringUTF16(IDS_TASK_MANAGER)); | |
| 600 } | |
| 601 | |
| 602 void BrowserView::FetchHideStatusAreaProperty() { | |
| 603 #if defined(TOOLKIT_USES_GTK) | |
| 604 std::set<WmIpc::AtomType> state_atoms; | |
| 605 if (WmIpc::instance()->GetWindowState( | |
| 606 GTK_WIDGET(frame()->GetNativeWindow()), &state_atoms)) { | |
| 607 if (state_atoms.count(WmIpc::ATOM_CHROME_STATE_STATUS_HIDDEN)) { | |
| 608 has_hide_status_area_property_ = true; | |
| 609 return; | |
| 610 } | |
| 611 } | |
| 612 #endif | |
| 613 has_hide_status_area_property_ = false; | |
| 614 } | |
| 615 | |
| 616 void BrowserView::UpdateLayoutModeButtonVisibility() { | |
| 617 int count = 0; | |
| 618 for (BrowserList::const_iterator it = BrowserList::begin(); | |
| 619 it != BrowserList::end(); ++it) { | |
| 620 if ((*it)->is_type_tabbed()) { | |
| 621 ++count; | |
| 622 if (count >= 2) { | |
| 623 should_show_layout_mode_button_ = true; | |
| 624 return; | |
| 625 } | |
| 626 } | |
| 627 } | |
| 628 should_show_layout_mode_button_ = false; | |
| 629 } | |
| 630 | |
| 631 } // namespace chromeos | |
| 632 | |
| 633 // static | |
| 634 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | |
| 635 // Create a browser view for chromeos. | |
| 636 BrowserView* view; | |
| 637 if (browser->is_type_popup() || browser->is_type_panel()) | |
| 638 view = new chromeos::PanelBrowserView(browser); | |
| 639 else | |
| 640 view = new chromeos::BrowserView(browser); | |
| 641 (new BrowserFrame(view))->InitBrowserFrame(); | |
| 642 return view; | |
| 643 } | |
| OLD | NEW |