| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 private: | 424 private: |
| 425 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); | 425 DISALLOW_COPY_AND_ASSIGN(ResizeCorner); |
| 426 }; | 426 }; |
| 427 | 427 |
| 428 /////////////////////////////////////////////////////////////////////////////// | 428 /////////////////////////////////////////////////////////////////////////////// |
| 429 // BrowserView, public: | 429 // BrowserView, public: |
| 430 | 430 |
| 431 BrowserView::BrowserView(Browser* browser) | 431 BrowserView::BrowserView() |
| 432 : views::ClientView(NULL, NULL), | 432 : views::ClientView(NULL, NULL), |
| 433 last_focused_view_storage_id_( | 433 last_focused_view_storage_id_( |
| 434 views::ViewStorage::GetInstance()->CreateStorageID()), | 434 views::ViewStorage::GetInstance()->CreateStorageID()), |
| 435 frame_(NULL), | 435 frame_(NULL), |
| 436 browser_(browser), | |
| 437 top_container_(NULL), | 436 top_container_(NULL), |
| 438 tabstrip_(NULL), | 437 tabstrip_(NULL), |
| 439 toolbar_(NULL), | 438 toolbar_(NULL), |
| 440 window_switcher_button_(NULL), | 439 window_switcher_button_(NULL), |
| 441 infobar_container_(NULL), | 440 infobar_container_(NULL), |
| 442 contents_web_view_(NULL), | 441 contents_web_view_(NULL), |
| 443 devtools_container_(NULL), | 442 devtools_container_(NULL), |
| 444 contents_container_(NULL), | 443 contents_container_(NULL), |
| 445 contents_split_(NULL), | 444 contents_split_(NULL), |
| 446 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM), | 445 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM), |
| 447 devtools_window_(NULL), | 446 devtools_window_(NULL), |
| 448 initialized_(false), | 447 initialized_(false), |
| 449 ignore_layout_(true), | 448 ignore_layout_(true), |
| 450 #if defined(OS_WIN) && !defined(USE_AURA) | 449 #if defined(OS_WIN) && !defined(USE_AURA) |
| 451 hung_window_detector_(&hung_plugin_action_), | 450 hung_window_detector_(&hung_plugin_action_), |
| 452 ticker_(0), | 451 ticker_(0), |
| 453 #endif | 452 #endif |
| 454 force_location_bar_focus_(false), | 453 force_location_bar_focus_(false), |
| 455 immersive_mode_controller_(chrome::CreateImmersiveModeController()), | 454 immersive_mode_controller_(chrome::CreateImmersiveModeController()), |
| 456 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)), | 455 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)), |
| 457 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) { | 456 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) { |
| 458 browser_->tab_strip_model()->AddObserver(this); | |
| 459 } | 457 } |
| 460 | 458 |
| 461 BrowserView::~BrowserView() { | 459 BrowserView::~BrowserView() { |
| 462 #if defined(USE_ASH) | 460 #if defined(USE_ASH) |
| 463 // Destroy BrowserLauncherItemController early on as it listens to the | 461 // Destroy BrowserLauncherItemController early on as it listens to the |
| 464 // TabstripModel, which is destroyed by the browser. | 462 // TabstripModel, which is destroyed by the browser. |
| 465 launcher_item_controller_.reset(); | 463 launcher_item_controller_.reset(); |
| 466 #endif | 464 #endif |
| 467 | 465 |
| 468 // Immersive mode may need to reparent views before they are removed/deleted. | 466 // Immersive mode may need to reparent views before they are removed/deleted. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 501 |
| 504 // It is possible that we were forced-closed by the native view system and | 502 // It is possible that we were forced-closed by the native view system and |
| 505 // that tabs remain in the browser. Close any such remaining tabs. | 503 // that tabs remain in the browser. Close any such remaining tabs. |
| 506 while (browser_->tab_strip_model()->count()) | 504 while (browser_->tab_strip_model()->count()) |
| 507 delete browser_->tab_strip_model()->GetWebContentsAt(0); | 505 delete browser_->tab_strip_model()->GetWebContentsAt(0); |
| 508 | 506 |
| 509 // Explicitly set browser_ to NULL. | 507 // Explicitly set browser_ to NULL. |
| 510 browser_.reset(); | 508 browser_.reset(); |
| 511 } | 509 } |
| 512 | 510 |
| 511 void BrowserView::Init(Browser* browser) { |
| 512 browser_.reset(browser); |
| 513 browser_->tab_strip_model()->AddObserver(this); |
| 514 } |
| 515 |
| 513 // static | 516 // static |
| 514 BrowserView* BrowserView::GetBrowserViewForNativeWindow( | 517 BrowserView* BrowserView::GetBrowserViewForNativeWindow( |
| 515 gfx::NativeWindow window) { | 518 gfx::NativeWindow window) { |
| 516 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 519 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 517 return widget ? | 520 return widget ? |
| 518 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( | 521 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( |
| 519 kBrowserViewKey)) : NULL; | 522 kBrowserViewKey)) : NULL; |
| 520 } | 523 } |
| 521 | 524 |
| 522 // static | 525 // static |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 child->Paint(canvas); | 1919 child->Paint(canvas); |
| 1917 } | 1920 } |
| 1918 | 1921 |
| 1919 infobar_container_->Paint(canvas); | 1922 infobar_container_->Paint(canvas); |
| 1920 } | 1923 } |
| 1921 | 1924 |
| 1922 void BrowserView::ViewHierarchyChanged(bool is_add, | 1925 void BrowserView::ViewHierarchyChanged(bool is_add, |
| 1923 views::View* parent, | 1926 views::View* parent, |
| 1924 views::View* child) { | 1927 views::View* child) { |
| 1925 if (!initialized_ && is_add && child == this && GetWidget()) { | 1928 if (!initialized_ && is_add && child == this && GetWidget()) { |
| 1926 Init(); | 1929 InitViews(); |
| 1927 initialized_ = true; | 1930 initialized_ = true; |
| 1928 } | 1931 } |
| 1929 } | 1932 } |
| 1930 | 1933 |
| 1931 void BrowserView::ChildPreferredSizeChanged(View* child) { | 1934 void BrowserView::ChildPreferredSizeChanged(View* child) { |
| 1932 Layout(); | 1935 Layout(); |
| 1933 } | 1936 } |
| 1934 | 1937 |
| 1935 void BrowserView::GetAccessibleState(ui::AccessibleViewState* state) { | 1938 void BrowserView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 1936 state->role = ui::AccessibilityTypes::ROLE_CLIENT; | 1939 state->role = ui::AccessibilityTypes::ROLE_CLIENT; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2008 sender->child_at(i)->InvalidateLayout(); | 2011 sender->child_at(i)->InvalidateLayout(); |
| 2009 SchedulePaint(); | 2012 SchedulePaint(); |
| 2010 Layout(); | 2013 Layout(); |
| 2011 return false; | 2014 return false; |
| 2012 } | 2015 } |
| 2013 | 2016 |
| 2014 void BrowserView::OnSysColorChange() { | 2017 void BrowserView::OnSysColorChange() { |
| 2015 chrome::MaybeShowInvertBubbleView(browser_.get(), contents_container_); | 2018 chrome::MaybeShowInvertBubbleView(browser_.get(), contents_container_); |
| 2016 } | 2019 } |
| 2017 | 2020 |
| 2018 void BrowserView::Init() { | 2021 void BrowserView::InitViews() { |
| 2019 GetWidget()->AddObserver(this); | 2022 GetWidget()->AddObserver(this); |
| 2020 | 2023 |
| 2021 SetLayoutManager(new BrowserViewLayout); | 2024 SetLayoutManager(new BrowserViewLayout(browser())); |
| 2022 // Stow a pointer to this object onto the window handle so that we can get at | 2025 // Stow a pointer to this object onto the window handle so that we can get at |
| 2023 // it later when all we have is a native view. | 2026 // it later when all we have is a native view. |
| 2024 GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this); | 2027 GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this); |
| 2025 | 2028 |
| 2026 // Stow a pointer to the browser's profile onto the window handle so that we | 2029 // Stow a pointer to the browser's profile onto the window handle so that we |
| 2027 // can get it later when all we have is a native view. | 2030 // can get it later when all we have is a native view. |
| 2028 GetWidget()->SetNativeWindowProperty(Profile::kProfileKey, | 2031 GetWidget()->SetNativeWindowProperty(Profile::kProfileKey, |
| 2029 browser_->profile()); | 2032 browser_->profile()); |
| 2030 | 2033 |
| 2031 // Initialize after |this| has a Widget and native window. | 2034 // Initialize after |this| has a Widget and native window. |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 launcher_item_controller_.reset( | 2607 launcher_item_controller_.reset( |
| 2605 BrowserLauncherItemController::Create(browser_.get())); | 2608 BrowserLauncherItemController::Create(browser_.get())); |
| 2606 } | 2609 } |
| 2607 #endif // defined(USE_ASH) | 2610 #endif // defined(USE_ASH) |
| 2608 } | 2611 } |
| 2609 | 2612 |
| 2610 // static | 2613 // static |
| 2611 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2614 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
| 2612 // Create the view and the frame. The frame will attach itself via the view | 2615 // Create the view and the frame. The frame will attach itself via the view |
| 2613 // so we don't need to do anything with the pointer. | 2616 // so we don't need to do anything with the pointer. |
| 2614 BrowserView* view = new BrowserView(browser); | 2617 BrowserView* view = new BrowserView(); |
| 2618 view->Init(browser); |
| 2615 (new BrowserFrame(view))->InitBrowserFrame(); | 2619 (new BrowserFrame(view))->InitBrowserFrame(); |
| 2616 view->GetWidget()->non_client_view()->SetAccessibleName( | 2620 view->GetWidget()->non_client_view()->SetAccessibleName( |
| 2617 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 2621 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 2618 return view; | 2622 return view; |
| 2619 } | 2623 } |
| 2620 | 2624 |
| 2621 void BrowserView::ShowAvatarBubble(WebContents* web_contents, | 2625 void BrowserView::ShowAvatarBubble(WebContents* web_contents, |
| 2622 const gfx::Rect& rect) { | 2626 const gfx::Rect& rect) { |
| 2623 gfx::Point origin(rect.origin()); | 2627 gfx::Point origin(rect.origin()); |
| 2624 views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin); | 2628 views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2728 | 2732 |
| 2729 Browser* modal_browser = | 2733 Browser* modal_browser = |
| 2730 chrome::FindBrowserWithWebContents(active_dialog->web_contents()); | 2734 chrome::FindBrowserWithWebContents(active_dialog->web_contents()); |
| 2731 if (modal_browser && (browser_ != modal_browser)) { | 2735 if (modal_browser && (browser_ != modal_browser)) { |
| 2732 modal_browser->window()->FlashFrame(true); | 2736 modal_browser->window()->FlashFrame(true); |
| 2733 modal_browser->window()->Activate(); | 2737 modal_browser->window()->Activate(); |
| 2734 } | 2738 } |
| 2735 | 2739 |
| 2736 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); | 2740 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); |
| 2737 } | 2741 } |
| OLD | NEW |