OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 | 6 |
7 #include "chrome/browser/views/frame/browser_view.h" | 7 #include "chrome/browser/views/frame/browser_view.h" |
8 | 8 |
9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/views/download_shelf_view.h" | 23 #include "chrome/browser/views/download_shelf_view.h" |
24 #include "chrome/browser/views/frame/browser_frame.h" | 24 #include "chrome/browser/views/frame/browser_frame.h" |
25 #include "chrome/browser/views/html_dialog_view.h" | 25 #include "chrome/browser/views/html_dialog_view.h" |
26 #include "chrome/browser/views/importer_view.h" | 26 #include "chrome/browser/views/importer_view.h" |
27 #include "chrome/browser/views/infobars/infobar_container.h" | 27 #include "chrome/browser/views/infobars/infobar_container.h" |
28 #include "chrome/browser/views/keyword_editor_view.h" | 28 #include "chrome/browser/views/keyword_editor_view.h" |
29 #include "chrome/browser/views/password_manager_view.h" | 29 #include "chrome/browser/views/password_manager_view.h" |
30 #include "chrome/browser/views/status_bubble_views.h" | 30 #include "chrome/browser/views/status_bubble_views.h" |
31 #include "chrome/browser/views/tab_contents_container_view.h" | 31 #include "chrome/browser/views/tab_contents_container_view.h" |
32 #include "chrome/browser/views/tabs/tab_strip.h" | 32 #include "chrome/browser/views/tabs/tab_strip.h" |
| 33 #include "chrome/browser/views/toolbar_star_toggle.h" |
33 #include "chrome/browser/views/toolbar_view.h" | 34 #include "chrome/browser/views/toolbar_view.h" |
34 #include "chrome/browser/tab_contents/navigation_entry.h" | 35 #include "chrome/browser/tab_contents/navigation_entry.h" |
35 #include "chrome/browser/tab_contents/web_contents.h" | 36 #include "chrome/browser/tab_contents/web_contents.h" |
36 #include "chrome/browser/tab_contents/web_contents_view.h" | 37 #include "chrome/browser/tab_contents/web_contents_view.h" |
37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/drag_drop_types.h" | 39 #include "chrome/common/drag_drop_types.h" |
39 #include "chrome/common/l10n_util.h" | 40 #include "chrome/common/l10n_util.h" |
40 #include "chrome/common/notification_service.h" | 41 #include "chrome/common/notification_service.h" |
41 #include "chrome/common/os_exchange_data.h" | 42 #include "chrome/common/os_exchange_data.h" |
42 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
(...skipping 20 matching lines...) Expand all Loading... |
63 static const int kStatusBubbleHeight = 20; | 64 static const int kStatusBubbleHeight = 20; |
64 // The overlap of the status bubble with the left edge of the window. | 65 // The overlap of the status bubble with the left edge of the window. |
65 static const int kStatusBubbleHorizontalOverlap = 2; | 66 static const int kStatusBubbleHorizontalOverlap = 2; |
66 // The overlap of the status bubble with the bottom edge of the window. | 67 // The overlap of the status bubble with the bottom edge of the window. |
67 static const int kStatusBubbleVerticalOverlap = 2; | 68 static const int kStatusBubbleVerticalOverlap = 2; |
68 // An offset distance between certain toolbars and the toolbar that preceded | 69 // An offset distance between certain toolbars and the toolbar that preceded |
69 // them in layout. | 70 // them in layout. |
70 static const int kSeparationLineHeight = 1; | 71 static const int kSeparationLineHeight = 1; |
71 // The name of a key to store on the window handle so that other code can | 72 // The name of a key to store on the window handle so that other code can |
72 // locate this object using just the handle. | 73 // locate this object using just the handle. |
73 static const wchar_t* kBrowserWindowKey = L"__BROWSER_WINDOW__"; | 74 static const wchar_t* kBrowserViewKey = L"__BROWSER_VIEW__"; |
74 // The distance between tiled windows. | 75 // The distance between tiled windows. |
75 static const int kWindowTilePixels = 10; | 76 static const int kWindowTilePixels = 10; |
76 // How frequently we check for hung plugin windows. | 77 // How frequently we check for hung plugin windows. |
77 static const int kDefaultHungPluginDetectFrequency = 2000; | 78 static const int kDefaultHungPluginDetectFrequency = 2000; |
78 // How long do we wait before we consider a window hung (in ms). | 79 // How long do we wait before we consider a window hung (in ms). |
79 static const int kDefaultPluginMessageResponseTimeout = 30000; | 80 static const int kDefaultPluginMessageResponseTimeout = 30000; |
80 // The number of milliseconds between loading animation frames. | 81 // The number of milliseconds between loading animation frames. |
81 static const int kLoadingAnimationFrameTimeMs = 30; | 82 static const int kLoadingAnimationFrameTimeMs = 30; |
82 | 83 |
83 static const struct { bool separator; int command; int label; } kMenuLayout[] =
{ | 84 static const struct { bool separator; int command; int label; } kMenuLayout[] =
{ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 BrowserView::~BrowserView() { | 135 BrowserView::~BrowserView() { |
135 browser_->tabstrip_model()->RemoveObserver(this); | 136 browser_->tabstrip_model()->RemoveObserver(this); |
136 | 137 |
137 // Stop hung plugin monitoring. | 138 // Stop hung plugin monitoring. |
138 ticker_.Stop(); | 139 ticker_.Stop(); |
139 ticker_.UnregisterTickHandler(&hung_window_detector_); | 140 ticker_.UnregisterTickHandler(&hung_window_detector_); |
140 } | 141 } |
141 | 142 |
142 // static | 143 // static |
143 BrowserWindow* BrowserView::GetBrowserWindowForHWND(HWND window) { | 144 BrowserView* BrowserView::GetBrowserViewForHWND(HWND window) { |
144 if (IsWindow(window)) { | 145 if (IsWindow(window)) { |
145 HANDLE data = GetProp(window, kBrowserWindowKey); | 146 HANDLE data = GetProp(window, kBrowserViewKey); |
146 if (data) | 147 if (data) |
147 return reinterpret_cast<BrowserWindow*>(data); | 148 return reinterpret_cast<BrowserView*>(data); |
148 } | 149 } |
149 return NULL; | 150 return NULL; |
150 } | 151 } |
151 | 152 |
152 int BrowserView::GetShowState() const { | 153 int BrowserView::GetShowState() const { |
153 STARTUPINFO si = {0}; | 154 STARTUPINFO si = {0}; |
154 si.cb = sizeof(si); | 155 si.cb = sizeof(si); |
155 si.dwFlags = STARTF_USESHOWWINDOW; | 156 si.dwFlags = STARTF_USESHOWWINDOW; |
156 GetStartupInfo(&si); | 157 GetStartupInfo(&si); |
157 // When launched from bash, for some reason si.wShowWindow is set to SW_HIDE, | 158 // When launched from bash, for some reason si.wShowWindow is set to SW_HIDE, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, | 317 prefs->RegisterIntegerPref(prefs::kHungPluginDetectFrequency, |
317 kDefaultHungPluginDetectFrequency); | 318 kDefaultHungPluginDetectFrequency); |
318 } | 319 } |
319 | 320 |
320 /////////////////////////////////////////////////////////////////////////////// | 321 /////////////////////////////////////////////////////////////////////////////// |
321 // BrowserView, BrowserWindow implementation: | 322 // BrowserView, BrowserWindow implementation: |
322 | 323 |
323 void BrowserView::Init() { | 324 void BrowserView::Init() { |
324 // Stow a pointer to this object onto the window handle so that we can get | 325 // Stow a pointer to this object onto the window handle so that we can get |
325 // at it later when all we have is a HWND. | 326 // at it later when all we have is a HWND. |
326 SetProp(GetWidget()->GetHWND(), kBrowserWindowKey, this); | 327 SetProp(GetWidget()->GetHWND(), kBrowserViewKey, this); |
327 | 328 |
328 // Start a hung plugin window detector for this browser object (as long as | 329 // Start a hung plugin window detector for this browser object (as long as |
329 // hang detection is not disabled). | 330 // hang detection is not disabled). |
330 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 331 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
331 switches::kDisableHangMonitor)) { | 332 switches::kDisableHangMonitor)) { |
332 InitHangMonitor(); | 333 InitHangMonitor(); |
333 } | 334 } |
334 | 335 |
335 LoadAccelerators(); | 336 LoadAccelerators(); |
336 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); | 337 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 417 } |
417 | 418 |
418 void* BrowserView::GetNativeHandle() { | 419 void* BrowserView::GetNativeHandle() { |
419 return GetWidget()->GetHWND(); | 420 return GetWidget()->GetHWND(); |
420 } | 421 } |
421 | 422 |
422 BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() { | 423 BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() { |
423 return this; | 424 return this; |
424 } | 425 } |
425 | 426 |
426 TabStrip* BrowserView::GetTabStrip() const { | |
427 return tabstrip_; | |
428 } | |
429 | |
430 StatusBubble* BrowserView::GetStatusBubble() { | 427 StatusBubble* BrowserView::GetStatusBubble() { |
431 return status_bubble_.get(); | 428 return status_bubble_.get(); |
432 } | 429 } |
433 | 430 |
434 void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) { | 431 void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) { |
435 if (is_animating) { | 432 if (is_animating) { |
436 contents_container_->set_fast_resize(true); | 433 contents_container_->set_fast_resize(true); |
437 UpdateUIForContents(browser_->GetSelectedTabContents()); | 434 UpdateUIForContents(browser_->GetSelectedTabContents()); |
438 contents_container_->set_fast_resize(false); | 435 contents_container_->set_fast_resize(false); |
439 } else { | 436 } else { |
(...skipping 18 matching lines...) Expand all Loading... |
458 } | 455 } |
459 } else { | 456 } else { |
460 if (loading_animation_timer_.IsRunning()) { | 457 if (loading_animation_timer_.IsRunning()) { |
461 loading_animation_timer_.Stop(); | 458 loading_animation_timer_.Stop(); |
462 // Loads are now complete, update the state if a task was scheduled. | 459 // Loads are now complete, update the state if a task was scheduled. |
463 LoadingAnimationCallback(); | 460 LoadingAnimationCallback(); |
464 } | 461 } |
465 } | 462 } |
466 } | 463 } |
467 | 464 |
| 465 void BrowserView::SetStarredState(bool is_starred) { |
| 466 toolbar_->star_button()->SetToggled(is_starred); |
| 467 } |
| 468 |
468 gfx::Rect BrowserView::GetNormalBounds() const { | 469 gfx::Rect BrowserView::GetNormalBounds() const { |
469 WINDOWPLACEMENT wp; | 470 WINDOWPLACEMENT wp; |
470 wp.length = sizeof(wp); | 471 wp.length = sizeof(wp); |
471 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); | 472 const bool ret = !!GetWindowPlacement(frame_->GetWindow()->GetHWND(), &wp); |
472 DCHECK(ret); | 473 DCHECK(ret); |
473 return gfx::Rect(wp.rcNormalPosition); | 474 return gfx::Rect(wp.rcNormalPosition); |
474 } | 475 } |
475 | 476 |
476 bool BrowserView::IsMaximized() { | 477 bool BrowserView::IsMaximized() { |
477 return frame_->GetWindow()->IsMaximized(); | 478 return frame_->GetWindow()->IsMaximized(); |
478 } | 479 } |
479 | 480 |
480 ToolbarStarToggle* BrowserView::GetStarButton() const { | |
481 return toolbar_->star_button(); | |
482 } | |
483 | |
484 LocationBarView* BrowserView::GetLocationBarView() const { | 481 LocationBarView* BrowserView::GetLocationBarView() const { |
485 return toolbar_->GetLocationBarView(); | 482 return toolbar_->GetLocationBarView(); |
486 } | 483 } |
487 | 484 |
488 GoButton* BrowserView::GetGoButton() const { | 485 BrowserView* BrowserView::GetBrowserView() const { |
489 return toolbar_->GetGoButton(); | 486 return NULL; |
490 } | 487 } |
491 | 488 |
492 BrowserView* BrowserView::GetBrowserView() const { | 489 void BrowserView::UpdateStopGoState(bool is_loading) { |
493 return NULL; | 490 toolbar_->GetGoButton()->ChangeMode( |
| 491 is_loading ? GoButton::MODE_STOP : GoButton::MODE_GO); |
494 } | 492 } |
495 | 493 |
496 void BrowserView::UpdateToolbar(TabContents* contents, | 494 void BrowserView::UpdateToolbar(TabContents* contents, |
497 bool should_restore_state) { | 495 bool should_restore_state) { |
498 toolbar_->Update(contents, should_restore_state); | 496 toolbar_->Update(contents, should_restore_state); |
499 } | 497 } |
500 | 498 |
501 void BrowserView::FocusToolbar() { | 499 void BrowserView::FocusToolbar() { |
502 // Do not restore the button that previously had accessibility focus, if | 500 // Do not restore the button that previously had accessibility focus, if |
503 // focus is set by using the toolbar focus keyboard shortcut. | 501 // focus is set by using the toolbar focus keyboard shortcut. |
(...skipping 27 matching lines...) Expand all Loading... |
531 void BrowserView::ShowAboutChromeDialog() { | 529 void BrowserView::ShowAboutChromeDialog() { |
532 views::Window::CreateChromeWindow( | 530 views::Window::CreateChromeWindow( |
533 GetWidget()->GetHWND(), gfx::Rect(), | 531 GetWidget()->GetHWND(), gfx::Rect(), |
534 new AboutChromeView(browser_->profile()))->Show(); | 532 new AboutChromeView(browser_->profile()))->Show(); |
535 } | 533 } |
536 | 534 |
537 void BrowserView::ShowBookmarkManager() { | 535 void BrowserView::ShowBookmarkManager() { |
538 BookmarkManagerView::Show(browser_->profile()); | 536 BookmarkManagerView::Show(browser_->profile()); |
539 } | 537 } |
540 | 538 |
| 539 bool BrowserView::IsBookmarkBubbleVisible() const { |
| 540 return toolbar_->star_button()->is_bubble_showing(); |
| 541 } |
| 542 |
| 543 void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) { |
| 544 toolbar_->star_button()->ShowStarBubble(url, !already_bookmarked); |
| 545 } |
| 546 |
541 void BrowserView::ShowReportBugDialog() { | 547 void BrowserView::ShowReportBugDialog() { |
542 // Retrieve the URL for the current tab (if any) and tell the BugReportView | 548 // Retrieve the URL for the current tab (if any) and tell the BugReportView |
543 TabContents* current_tab = browser_->GetSelectedTabContents(); | 549 TabContents* current_tab = browser_->GetSelectedTabContents(); |
544 if (!current_tab) | 550 if (!current_tab) |
545 return; | 551 return; |
546 | 552 |
547 BugReportView* bug_report_view = new BugReportView(browser_->profile(), | 553 BugReportView* bug_report_view = new BugReportView(browser_->profile(), |
548 current_tab); | 554 current_tab); |
549 | 555 |
550 if (current_tab->controller()->GetLastCommittedEntry()) { | 556 if (current_tab->controller()->GetLastCommittedEntry()) { |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 | 1376 |
1371 // static | 1377 // static |
1372 void BrowserView::InitClass() { | 1378 void BrowserView::InitClass() { |
1373 static bool initialized = false; | 1379 static bool initialized = false; |
1374 if (!initialized) { | 1380 if (!initialized) { |
1375 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1381 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1376 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 1382 default_favicon_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
1377 initialized = true; | 1383 initialized = true; |
1378 } | 1384 } |
1379 } | 1385 } |
OLD | NEW |