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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" | 61 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" |
62 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 62 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
63 #include "chrome/browser/ui/views/avatar_menu_button.h" | 63 #include "chrome/browser/ui/views/avatar_menu_button.h" |
64 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 64 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
65 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" | 65 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" |
66 #include "chrome/browser/ui/views/browser_dialogs.h" | 66 #include "chrome/browser/ui/views/browser_dialogs.h" |
67 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" | 67 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" |
68 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 68 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
69 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 69 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
70 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" | 70 #include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h" |
71 #include "chrome/browser/ui/views/frame/contents_container.h" | 71 #include "chrome/browser/ui/views/frame/contents_layout_manager.h" |
72 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 72 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
73 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" | 73 #include "chrome/browser/ui/views/frame/native_browser_frame_factory.h" |
74 #include "chrome/browser/ui/views/frame/top_container_view.h" | 74 #include "chrome/browser/ui/views/frame/top_container_view.h" |
75 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" | 75 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" |
76 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 76 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
77 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 77 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
78 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 78 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
79 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 79 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
80 #include "chrome/browser/ui/views/password_generation_bubble_view.h" | 80 #include "chrome/browser/ui/views/password_generation_bubble_view.h" |
81 #include "chrome/browser/ui/views/profile_chooser_view.h" | 81 #include "chrome/browser/ui/views/profile_chooser_view.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #include "ui/base/hit_test.h" | 113 #include "ui/base/hit_test.h" |
114 #include "ui/base/l10n/l10n_util.h" | 114 #include "ui/base/l10n/l10n_util.h" |
115 #include "ui/base/resource/resource_bundle.h" | 115 #include "ui/base/resource/resource_bundle.h" |
116 #include "ui/base/theme_provider.h" | 116 #include "ui/base/theme_provider.h" |
117 #include "ui/events/event_utils.h" | 117 #include "ui/events/event_utils.h" |
118 #include "ui/gfx/canvas.h" | 118 #include "ui/gfx/canvas.h" |
119 #include "ui/gfx/color_utils.h" | 119 #include "ui/gfx/color_utils.h" |
120 #include "ui/gfx/rect_conversions.h" | 120 #include "ui/gfx/rect_conversions.h" |
121 #include "ui/gfx/sys_color_change_listener.h" | 121 #include "ui/gfx/sys_color_change_listener.h" |
122 #include "ui/views/controls/button/menu_button.h" | 122 #include "ui/views/controls/button/menu_button.h" |
123 #include "ui/views/controls/single_split_view.h" | |
124 #include "ui/views/controls/textfield/textfield.h" | 123 #include "ui/views/controls/textfield/textfield.h" |
125 #include "ui/views/controls/webview/webview.h" | 124 #include "ui/views/controls/webview/webview.h" |
126 #include "ui/views/focus/external_focus_tracker.h" | 125 #include "ui/views/focus/external_focus_tracker.h" |
127 #include "ui/views/focus/view_storage.h" | 126 #include "ui/views/focus/view_storage.h" |
128 #include "ui/views/layout/grid_layout.h" | 127 #include "ui/views/layout/grid_layout.h" |
129 #include "ui/views/widget/native_widget.h" | 128 #include "ui/views/widget/native_widget.h" |
130 #include "ui/views/widget/root_view.h" | 129 #include "ui/views/widget/root_view.h" |
131 #include "ui/views/widget/widget.h" | 130 #include "ui/views/widget/widget.h" |
132 #include "ui/views/window/dialog_delegate.h" | 131 #include "ui/views/window/dialog_delegate.h" |
133 | 132 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 last_focused_view_storage_id_( | 407 last_focused_view_storage_id_( |
409 views::ViewStorage::GetInstance()->CreateStorageID()), | 408 views::ViewStorage::GetInstance()->CreateStorageID()), |
410 frame_(NULL), | 409 frame_(NULL), |
411 top_container_(NULL), | 410 top_container_(NULL), |
412 tabstrip_(NULL), | 411 tabstrip_(NULL), |
413 toolbar_(NULL), | 412 toolbar_(NULL), |
414 window_switcher_button_(NULL), | 413 window_switcher_button_(NULL), |
415 find_bar_host_view_(NULL), | 414 find_bar_host_view_(NULL), |
416 infobar_container_(NULL), | 415 infobar_container_(NULL), |
417 contents_web_view_(NULL), | 416 contents_web_view_(NULL), |
418 devtools_container_(NULL), | |
419 contents_container_(NULL), | 417 contents_container_(NULL), |
420 contents_split_(NULL), | |
421 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM), | |
422 devtools_window_(NULL), | 418 devtools_window_(NULL), |
423 initialized_(false), | 419 initialized_(false), |
424 in_process_fullscreen_(false), | 420 in_process_fullscreen_(false), |
425 #if defined(OS_WIN) && !defined(USE_AURA) | 421 #if defined(OS_WIN) && !defined(USE_AURA) |
426 hung_window_detector_(&hung_plugin_action_), | 422 hung_window_detector_(&hung_plugin_action_), |
427 ticker_(0), | 423 ticker_(0), |
428 #endif | 424 #endif |
429 force_location_bar_focus_(false), | 425 force_location_bar_focus_(false), |
430 immersive_mode_controller_(chrome::CreateImmersiveModeController()), | 426 immersive_mode_controller_(chrome::CreateImmersiveModeController()), |
431 #if defined(OS_CHROMEOS) | 427 #if defined(OS_CHROMEOS) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( | 499 reinterpret_cast<BrowserView*>(widget->GetNativeWindowProperty( |
504 kBrowserViewKey)) : NULL; | 500 kBrowserViewKey)) : NULL; |
505 } | 501 } |
506 | 502 |
507 // static | 503 // static |
508 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) { | 504 BrowserView* BrowserView::GetBrowserViewForBrowser(const Browser* browser) { |
509 return static_cast<BrowserView*>(browser->window()); | 505 return static_cast<BrowserView*>(browser->window()); |
510 } | 506 } |
511 | 507 |
512 void BrowserView::InitStatusBubble() { | 508 void BrowserView::InitStatusBubble() { |
513 status_bubble_.reset(new StatusBubbleViews(contents_container_)); | 509 status_bubble_.reset(new StatusBubbleViews(contents_web_view_)); |
514 } | 510 } |
515 | 511 |
516 gfx::Rect BrowserView::GetToolbarBounds() const { | 512 gfx::Rect BrowserView::GetToolbarBounds() const { |
517 gfx::Rect toolbar_bounds(toolbar_->bounds()); | 513 gfx::Rect toolbar_bounds(toolbar_->bounds()); |
518 if (toolbar_bounds.IsEmpty()) | 514 if (toolbar_bounds.IsEmpty()) |
519 return toolbar_bounds; | 515 return toolbar_bounds; |
520 // The apparent toolbar edges are outside the "real" toolbar edges. | 516 // The apparent toolbar edges are outside the "real" toolbar edges. |
521 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0); | 517 toolbar_bounds.Inset(-views::NonClientFrameView::kClientEdgeThickness, 0); |
522 return toolbar_bounds; | 518 return toolbar_bounds; |
523 } | 519 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (detached_changed && immersive_mode_controller_->IsEnabled()) | 776 if (detached_changed && immersive_mode_controller_->IsEnabled()) |
781 change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE; | 777 change_type = BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
782 | 778 |
783 bookmark_bar_view_->SetBookmarkBarState(new_state, change_type); | 779 bookmark_bar_view_->SetBookmarkBarState(new_state, change_type); |
784 } | 780 } |
785 if (MaybeShowBookmarkBar(GetActiveWebContents())) | 781 if (MaybeShowBookmarkBar(GetActiveWebContents())) |
786 Layout(); | 782 Layout(); |
787 } | 783 } |
788 | 784 |
789 void BrowserView::UpdateDevTools() { | 785 void BrowserView::UpdateDevTools() { |
790 UpdateDevToolsForContents(GetActiveWebContents()); | 786 UpdateDevToolsForContents(GetActiveWebContents(), true); |
791 Layout(); | 787 Layout(); |
792 } | 788 } |
793 | 789 |
794 void BrowserView::UpdateLoadingAnimations(bool should_animate) { | 790 void BrowserView::UpdateLoadingAnimations(bool should_animate) { |
795 if (should_animate) { | 791 if (should_animate) { |
796 if (!loading_animation_timer_.IsRunning()) { | 792 if (!loading_animation_timer_.IsRunning()) { |
797 // Loads are happening, and the timer isn't running, so start it. | 793 // Loads are happening, and the timer isn't running, so start it. |
798 last_animation_time_ = base::TimeTicks::Now(); | 794 last_animation_time_ = base::TimeTicks::Now(); |
799 loading_animation_timer_.Start(FROM_HERE, | 795 loading_animation_timer_.Start(FROM_HERE, |
800 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, | 796 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, |
(...skipping 29 matching lines...) Expand all Loading... |
830 // the WebContents window. | 826 // the WebContents window. |
831 bool change_tab_contents = | 827 bool change_tab_contents = |
832 contents_web_view_->web_contents() != new_contents; | 828 contents_web_view_->web_contents() != new_contents; |
833 | 829 |
834 // Update various elements that are interested in knowing the current | 830 // Update various elements that are interested in knowing the current |
835 // WebContents. | 831 // WebContents. |
836 | 832 |
837 // When we toggle the NTP floating bookmarks bar and/or the info bar, | 833 // When we toggle the NTP floating bookmarks bar and/or the info bar, |
838 // we don't want any WebContents to be attached, so that we | 834 // we don't want any WebContents to be attached, so that we |
839 // avoid an unnecessary resize and re-layout of a WebContents. | 835 // avoid an unnecessary resize and re-layout of a WebContents. |
840 if (change_tab_contents) | 836 if (change_tab_contents) { |
841 contents_web_view_->SetWebContents(NULL); | 837 contents_web_view_->SetWebContents(NULL); |
| 838 devtools_web_view_->SetWebContents(NULL); |
| 839 } |
842 infobar_container_->ChangeInfoBarService( | 840 infobar_container_->ChangeInfoBarService( |
843 InfoBarService::FromWebContents(new_contents)); | 841 InfoBarService::FromWebContents(new_contents)); |
844 if (bookmark_bar_view_.get()) { | 842 if (bookmark_bar_view_.get()) { |
845 bookmark_bar_view_->SetBookmarkBarState( | 843 bookmark_bar_view_->SetBookmarkBarState( |
846 browser_->bookmark_bar_state(), | 844 browser_->bookmark_bar_state(), |
847 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 845 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
848 } | 846 } |
849 UpdateUIForContents(new_contents); | 847 UpdateUIForContents(new_contents); |
850 | 848 |
851 // Layout for DevTools _before_ setting the main WebContents to avoid | 849 // Layout for DevTools _before_ setting the both main and devtools WebContents |
852 // toggling the size of the main WebContents. | 850 // to avoid toggling the size of any of them. |
853 UpdateDevToolsForContents(new_contents); | 851 UpdateDevToolsForContents(new_contents, !change_tab_contents); |
854 | 852 |
855 if (change_tab_contents) | 853 if (change_tab_contents) { |
856 contents_web_view_->SetWebContents(new_contents); | 854 contents_web_view_->SetWebContents(new_contents); |
| 855 // The second layout update should be no-op. It will just set the |
| 856 // DevTools WebContents. |
| 857 UpdateDevToolsForContents(new_contents, true); |
| 858 } |
857 | 859 |
858 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && | 860 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && |
859 GetWidget()->IsVisible()) { | 861 GetWidget()->IsVisible()) { |
860 // We only restore focus if our window is visible, to avoid invoking blur | 862 // We only restore focus if our window is visible, to avoid invoking blur |
861 // handlers when we are eventually shown. | 863 // handlers when we are eventually shown. |
862 new_contents->GetView()->RestoreFocus(); | 864 new_contents->GetView()->RestoreFocus(); |
863 } | 865 } |
864 | 866 |
865 // Update all the UI bits. | 867 // Update all the UI bits. |
866 UpdateTitleBar(); | 868 UpdateTitleBar(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 } | 1016 } |
1015 | 1017 |
1016 // When transitioning from animating to not animating we need to make sure the | 1018 // When transitioning from animating to not animating we need to make sure the |
1017 // contents_container_ gets layed out. If we don't do this and the bounds | 1019 // contents_container_ gets layed out. If we don't do this and the bounds |
1018 // haven't changed contents_container_ won't get a Layout out and we'll end up | 1020 // haven't changed contents_container_ won't get a Layout out and we'll end up |
1019 // with a gray rect because the clip wasn't updated. Note that a reentrant | 1021 // with a gray rect because the clip wasn't updated. Note that a reentrant |
1020 // call never needs to do this, because after it returns, the normal call | 1022 // call never needs to do this, because after it returns, the normal call |
1021 // wrapping it will do it. | 1023 // wrapping it will do it. |
1022 if ((call_state == NORMAL) && !is_animating) { | 1024 if ((call_state == NORMAL) && !is_animating) { |
1023 contents_web_view_->InvalidateLayout(); | 1025 contents_web_view_->InvalidateLayout(); |
1024 contents_split_->Layout(); | 1026 contents_container_->Layout(); |
1025 } | 1027 } |
1026 } | 1028 } |
1027 | 1029 |
1028 LocationBar* BrowserView::GetLocationBar() const { | 1030 LocationBar* BrowserView::GetLocationBar() const { |
1029 return GetLocationBarView(); | 1031 return GetLocationBarView(); |
1030 } | 1032 } |
1031 | 1033 |
1032 void BrowserView::SetFocusToLocationBar(bool select_all) { | 1034 void BrowserView::SetFocusToLocationBar(bool select_all) { |
1033 // On Windows, changing focus to the location bar causes the browser | 1035 // On Windows, changing focus to the location bar causes the browser |
1034 // window to become active. This can steal focus if the user has | 1036 // window to become active. This can steal focus if the user has |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 | 1283 |
1282 int BrowserView::GetExtraRenderViewHeight() const { | 1284 int BrowserView::GetExtraRenderViewHeight() const { |
1283 // Currently this is only used on linux. | 1285 // Currently this is only used on linux. |
1284 return 0; | 1286 return 0; |
1285 } | 1287 } |
1286 | 1288 |
1287 void BrowserView::WebContentsFocused(WebContents* contents) { | 1289 void BrowserView::WebContentsFocused(WebContents* contents) { |
1288 if (contents_web_view_->GetWebContents() == contents) | 1290 if (contents_web_view_->GetWebContents() == contents) |
1289 contents_web_view_->OnWebContentsFocused(contents); | 1291 contents_web_view_->OnWebContentsFocused(contents); |
1290 else | 1292 else |
1291 devtools_container_->OnWebContentsFocused(contents); | 1293 devtools_web_view_->OnWebContentsFocused(contents); |
1292 } | 1294 } |
1293 | 1295 |
1294 void BrowserView::ShowWebsiteSettings(Profile* profile, | 1296 void BrowserView::ShowWebsiteSettings(Profile* profile, |
1295 content::WebContents* web_contents, | 1297 content::WebContents* web_contents, |
1296 const GURL& url, | 1298 const GURL& url, |
1297 const content::SSLStatus& ssl) { | 1299 const content::SSLStatus& ssl) { |
1298 WebsiteSettingsPopupView::ShowPopup( | 1300 WebsiteSettingsPopupView::ShowPopup( |
1299 GetLocationBarView()->GetLocationIconView(), profile, | 1301 GetLocationBarView()->GetLocationIconView(), profile, |
1300 web_contents, url, ssl, browser_.get()); | 1302 web_contents, url, ssl, browser_.get()); |
1301 } | 1303 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 void BrowserView::TabDetachedAt(WebContents* contents, int index) { | 1468 void BrowserView::TabDetachedAt(WebContents* contents, int index) { |
1467 // We use index here rather than comparing |contents| because by this time | 1469 // We use index here rather than comparing |contents| because by this time |
1468 // the model has already removed |contents| from its list, so | 1470 // the model has already removed |contents| from its list, so |
1469 // browser_->GetActiveWebContents() will return NULL or something else. | 1471 // browser_->GetActiveWebContents() will return NULL or something else. |
1470 if (index == browser_->tab_strip_model()->active_index()) { | 1472 if (index == browser_->tab_strip_model()->active_index()) { |
1471 // We need to reset the current tab contents to NULL before it gets | 1473 // We need to reset the current tab contents to NULL before it gets |
1472 // freed. This is because the focus manager performs some operations | 1474 // freed. This is because the focus manager performs some operations |
1473 // on the selected WebContents when it is removed. | 1475 // on the selected WebContents when it is removed. |
1474 contents_web_view_->SetWebContents(NULL); | 1476 contents_web_view_->SetWebContents(NULL); |
1475 infobar_container_->ChangeInfoBarService(NULL); | 1477 infobar_container_->ChangeInfoBarService(NULL); |
1476 UpdateDevToolsForContents(NULL); | 1478 UpdateDevToolsForContents(NULL, true); |
1477 } | 1479 } |
1478 } | 1480 } |
1479 | 1481 |
1480 void BrowserView::TabDeactivated(WebContents* contents) { | 1482 void BrowserView::TabDeactivated(WebContents* contents) { |
1481 // We do not store the focus when closing the tab to work-around bug 4633. | 1483 // We do not store the focus when closing the tab to work-around bug 4633. |
1482 // Some reports seem to show that the focus manager and/or focused view can | 1484 // Some reports seem to show that the focus manager and/or focused view can |
1483 // be garbage at that point, it is not clear why. | 1485 // be garbage at that point, it is not clear why. |
1484 if (!contents->IsBeingDestroyed()) | 1486 if (!contents->IsBeingDestroyed()) |
1485 contents->GetView()->StoreFocus(); | 1487 contents->GetView()->StoreFocus(); |
1486 } | 1488 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 // invisible or has no focusable children, it will be automatically | 1745 // invisible or has no focusable children, it will be automatically |
1744 // skipped. | 1746 // skipped. |
1745 panes->push_back(toolbar_); | 1747 panes->push_back(toolbar_); |
1746 if (bookmark_bar_view_.get()) | 1748 if (bookmark_bar_view_.get()) |
1747 panes->push_back(bookmark_bar_view_.get()); | 1749 panes->push_back(bookmark_bar_view_.get()); |
1748 if (infobar_container_) | 1750 if (infobar_container_) |
1749 panes->push_back(infobar_container_); | 1751 panes->push_back(infobar_container_); |
1750 if (download_shelf_.get()) | 1752 if (download_shelf_.get()) |
1751 panes->push_back(download_shelf_.get()); | 1753 panes->push_back(download_shelf_.get()); |
1752 panes->push_back(GetTabContentsContainerView()); | 1754 panes->push_back(GetTabContentsContainerView()); |
1753 if (devtools_container_->visible()) | 1755 if (devtools_web_view_->visible()) |
1754 panes->push_back(devtools_container_); | 1756 panes->push_back(devtools_web_view_); |
1755 } | 1757 } |
1756 | 1758 |
1757 /////////////////////////////////////////////////////////////////////////////// | 1759 /////////////////////////////////////////////////////////////////////////////// |
1758 // BrowserView, views::ClientView overrides: | 1760 // BrowserView, views::ClientView overrides: |
1759 | 1761 |
1760 bool BrowserView::CanClose() { | 1762 bool BrowserView::CanClose() { |
1761 // You cannot close a frame for which there is an active originating drag | 1763 // You cannot close a frame for which there is an active originating drag |
1762 // session. | 1764 // session. |
1763 if (tabstrip_ && !tabstrip_->IsTabStripCloseable()) | 1765 if (tabstrip_ && !tabstrip_->IsTabStripCloseable()) |
1764 return false; | 1766 return false; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 | 1905 |
1904 bool BrowserView::DrawInfoBarArrows(int* x) const { | 1906 bool BrowserView::DrawInfoBarArrows(int* x) const { |
1905 if (x) { | 1907 if (x) { |
1906 gfx::Point anchor(toolbar_->location_bar()->GetLocationBarAnchorPoint()); | 1908 gfx::Point anchor(toolbar_->location_bar()->GetLocationBarAnchorPoint()); |
1907 ConvertPointToTarget(toolbar_->location_bar(), this, &anchor); | 1909 ConvertPointToTarget(toolbar_->location_bar(), this, &anchor); |
1908 *x = anchor.x(); | 1910 *x = anchor.x(); |
1909 } | 1911 } |
1910 return true; | 1912 return true; |
1911 } | 1913 } |
1912 | 1914 |
1913 bool BrowserView::SplitHandleMoved(views::SingleSplitView* sender) { | |
1914 for (int i = 0; i < sender->child_count(); ++i) | |
1915 sender->child_at(i)->InvalidateLayout(); | |
1916 SchedulePaint(); | |
1917 Layout(); | |
1918 return false; | |
1919 } | |
1920 | |
1921 void BrowserView::OnSysColorChange() { | 1915 void BrowserView::OnSysColorChange() { |
1922 chrome::MaybeShowInvertBubbleView(browser_.get(), contents_container_); | 1916 chrome::MaybeShowInvertBubbleView(browser_.get(), contents_container_); |
1923 } | 1917 } |
1924 | 1918 |
1925 void BrowserView::InitViews() { | 1919 void BrowserView::InitViews() { |
1926 GetWidget()->AddObserver(this); | 1920 GetWidget()->AddObserver(this); |
1927 | 1921 |
1928 // Stow a pointer to this object onto the window handle so that we can get at | 1922 // Stow a pointer to this object onto the window handle so that we can get at |
1929 // it later when all we have is a native view. | 1923 // it later when all we have is a native view. |
1930 GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this); | 1924 GetWidget()->SetNativeWindowProperty(kBrowserViewKey, this); |
(...skipping 13 matching lines...) Expand all Loading... |
1944 LoadAccelerators(); | 1938 LoadAccelerators(); |
1945 | 1939 |
1946 infobar_container_ = new InfoBarContainerView(this); | 1940 infobar_container_ = new InfoBarContainerView(this); |
1947 AddChildView(infobar_container_); | 1941 AddChildView(infobar_container_); |
1948 | 1942 |
1949 contents_web_view_ = new views::WebView(browser_->profile()); | 1943 contents_web_view_ = new views::WebView(browser_->profile()); |
1950 contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER); | 1944 contents_web_view_->set_id(VIEW_ID_TAB_CONTAINER); |
1951 contents_web_view_->SetEmbedFullscreenWidgetMode( | 1945 contents_web_view_->SetEmbedFullscreenWidgetMode( |
1952 implicit_cast<content::WebContentsDelegate*>(browser_.get())-> | 1946 implicit_cast<content::WebContentsDelegate*>(browser_.get())-> |
1953 EmbedsFullscreenWidget()); | 1947 EmbedsFullscreenWidget()); |
1954 contents_container_ = new ContentsContainer(contents_web_view_); | |
1955 | 1948 |
1956 SkColor bg_color = GetWidget()->GetThemeProvider()-> | 1949 devtools_web_view_ = new views::WebView(browser_->profile()); |
1957 GetColor(ThemeProperties::COLOR_TOOLBAR); | 1950 devtools_web_view_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); |
| 1951 devtools_web_view_->SetVisible(false); |
1958 | 1952 |
1959 devtools_container_ = new views::WebView(browser_->profile()); | 1953 contents_container_ = new views::View(); |
1960 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); | 1954 contents_container_->AddChildView(devtools_web_view_); |
1961 devtools_container_->SetVisible(false); | 1955 contents_container_->AddChildView(contents_web_view_); |
1962 | 1956 contents_container_->SetLayoutManager(new ContentsLayoutManager( |
1963 views::View* contents_container_view = contents_container_; | 1957 devtools_web_view_, contents_web_view_)); |
1964 | 1958 AddChildView(contents_container_); |
1965 contents_split_ = new views::SingleSplitView( | 1959 set_contents_view(contents_container_); |
1966 contents_container_view, | |
1967 devtools_container_, | |
1968 views::SingleSplitView::VERTICAL_SPLIT, | |
1969 this); | |
1970 contents_split_->set_id(VIEW_ID_CONTENTS_SPLIT); | |
1971 contents_split_->SetAccessibleName( | |
1972 l10n_util::GetStringUTF16(IDS_ACCNAME_WEB_CONTENTS)); | |
1973 contents_split_->set_background( | |
1974 views::Background::CreateSolidBackground(bg_color)); | |
1975 AddChildView(contents_split_); | |
1976 set_contents_view(contents_split_); | |
1977 | 1960 |
1978 InitStatusBubble(); | 1961 InitStatusBubble(); |
1979 | 1962 |
1980 // Top container holds tab strip and toolbar and lives at the front of the | 1963 // Top container holds tab strip and toolbar and lives at the front of the |
1981 // view hierarchy. | 1964 // view hierarchy. |
1982 top_container_ = new TopContainerView(this); | 1965 top_container_ = new TopContainerView(this); |
1983 AddChildView(top_container_); | 1966 AddChildView(top_container_); |
1984 | 1967 |
1985 // TabStrip takes ownership of the controller. | 1968 // TabStrip takes ownership of the controller. |
1986 BrowserTabStripController* tabstrip_controller = | 1969 BrowserTabStripController* tabstrip_controller = |
(...skipping 18 matching lines...) Expand all Loading... |
2005 immersive_mode_controller_->Init(this); | 1988 immersive_mode_controller_->Init(this); |
2006 | 1989 |
2007 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; | 1990 BrowserViewLayout* browser_view_layout = new BrowserViewLayout; |
2008 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), | 1991 browser_view_layout->Init(new BrowserViewLayoutDelegateImpl(this), |
2009 browser(), | 1992 browser(), |
2010 this, | 1993 this, |
2011 top_container_, | 1994 top_container_, |
2012 tabstrip_, | 1995 tabstrip_, |
2013 toolbar_, | 1996 toolbar_, |
2014 infobar_container_, | 1997 infobar_container_, |
2015 contents_split_, | |
2016 contents_container_, | 1998 contents_container_, |
| 1999 GetContentsLayoutManager(), |
2017 immersive_mode_controller_.get()); | 2000 immersive_mode_controller_.get()); |
2018 SetLayoutManager(browser_view_layout); | 2001 SetLayoutManager(browser_view_layout); |
2019 | 2002 |
2020 #if defined(OS_WIN) && !defined(USE_AURA) | 2003 #if defined(OS_WIN) && !defined(USE_AURA) |
2021 // Create a custom JumpList and add it to an observer of TabRestoreService | 2004 // Create a custom JumpList and add it to an observer of TabRestoreService |
2022 // so we can update the custom JumpList when a tab is added or removed. | 2005 // so we can update the custom JumpList when a tab is added or removed. |
2023 if (JumpList::Enabled()) { | 2006 if (JumpList::Enabled()) { |
2024 load_complete_listener_.reset(new LoadCompleteListener(this)); | 2007 load_complete_listener_.reset(new LoadCompleteListener(this)); |
2025 } | 2008 } |
2026 #endif | 2009 #endif |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 DCHECK(!jumplist_); | 2042 DCHECK(!jumplist_); |
2060 jumplist_ = new JumpList(); | 2043 jumplist_ = new JumpList(); |
2061 jumplist_->AddObserver(browser_->profile()); | 2044 jumplist_->AddObserver(browser_->profile()); |
2062 #endif | 2045 #endif |
2063 } | 2046 } |
2064 | 2047 |
2065 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { | 2048 BrowserViewLayout* BrowserView::GetBrowserViewLayout() const { |
2066 return static_cast<BrowserViewLayout*>(GetLayoutManager()); | 2049 return static_cast<BrowserViewLayout*>(GetLayoutManager()); |
2067 } | 2050 } |
2068 | 2051 |
| 2052 ContentsLayoutManager* BrowserView::GetContentsLayoutManager() const { |
| 2053 return static_cast<ContentsLayoutManager*>( |
| 2054 contents_container_->GetLayoutManager()); |
| 2055 } |
| 2056 |
2069 void BrowserView::LayoutStatusBubble() { | 2057 void BrowserView::LayoutStatusBubble() { |
2070 // In restored mode, the client area has a client edge between it and the | 2058 // In restored mode, the client area has a client edge between it and the |
2071 // frame. | 2059 // frame. |
2072 int overlap = StatusBubbleViews::kShadowThickness; | 2060 int overlap = StatusBubbleViews::kShadowThickness; |
2073 // The extra pixels defined by kClientEdgeThickness is only drawn in frame | 2061 // The extra pixels defined by kClientEdgeThickness is only drawn in frame |
2074 // content border on windows for non-aura build. | 2062 // content border on windows for non-aura build. |
2075 #if !defined(USE_ASH) | 2063 #if !defined(USE_ASH) |
2076 overlap += | 2064 overlap += |
2077 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness; | 2065 IsMaximized() ? 0 : views::NonClientFrameView::kClientEdgeThickness; |
2078 #endif | 2066 #endif |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 } | 2130 } |
2143 } | 2131 } |
2144 | 2132 |
2145 bool BrowserView::MaybeShowInfoBar(WebContents* contents) { | 2133 bool BrowserView::MaybeShowInfoBar(WebContents* contents) { |
2146 // TODO(beng): Remove this function once the interface between | 2134 // TODO(beng): Remove this function once the interface between |
2147 // InfoBarContainer, DownloadShelfView and WebContents and this | 2135 // InfoBarContainer, DownloadShelfView and WebContents and this |
2148 // view is sorted out. | 2136 // view is sorted out. |
2149 return true; | 2137 return true; |
2150 } | 2138 } |
2151 | 2139 |
2152 void BrowserView::UpdateDevToolsForContents(WebContents* web_contents) { | 2140 void BrowserView::UpdateDevToolsForContents( |
| 2141 WebContents* web_contents, bool update_devtools_web_contents) { |
2153 DevToolsWindow* new_devtools_window = web_contents ? | 2142 DevToolsWindow* new_devtools_window = web_contents ? |
2154 DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL; | 2143 DevToolsWindow::GetDockedInstanceForInspectedTab(web_contents) : NULL; |
2155 // Fast return in case of the same window having same orientation. | 2144 |
2156 if (devtools_window_ == new_devtools_window) { | 2145 // Replace devtools WebContents. |
2157 if (!new_devtools_window || | 2146 WebContents* new_contents = new_devtools_window ? |
2158 (new_devtools_window->dock_side() == devtools_dock_side_)) { | 2147 new_devtools_window->web_contents() : NULL; |
2159 return; | 2148 if (devtools_web_view_->web_contents() != new_contents && |
2160 } | 2149 update_devtools_web_contents) { |
| 2150 devtools_web_view_->SetWebContents(new_contents); |
2161 } | 2151 } |
2162 | 2152 |
2163 // Replace tab contents. | 2153 if (!devtools_window_ && new_devtools_window && |
2164 if (devtools_window_ != new_devtools_window) { | 2154 !devtools_focus_tracker_.get()) { |
2165 devtools_container_->SetWebContents( | |
2166 new_devtools_window ? new_devtools_window->web_contents() : NULL); | |
2167 } | |
2168 | |
2169 // Store last used position. | |
2170 if (devtools_window_) { | |
2171 int split_size = contents_split_->GetDividerSize(); | |
2172 if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT) { | |
2173 devtools_window_->SetWidth(contents_split_->width() - | |
2174 split_size - contents_split_->divider_offset()); | |
2175 } else if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_BOTTOM) { | |
2176 devtools_window_->SetHeight(contents_split_->height() - | |
2177 split_size - contents_split_->divider_offset()); | |
2178 } | |
2179 } | |
2180 | |
2181 // Show / hide container if necessary. Changing dock orientation is | |
2182 // hide + show. | |
2183 bool should_hide = devtools_window_ && (!new_devtools_window || | |
2184 devtools_dock_side_ != new_devtools_window->dock_side()); | |
2185 bool should_show = new_devtools_window && (!devtools_window_ || should_hide); | |
2186 | |
2187 if (should_hide) | |
2188 HideDevToolsContainer(); | |
2189 | |
2190 devtools_window_ = new_devtools_window; | |
2191 | |
2192 if (should_show) { | |
2193 devtools_dock_side_ = new_devtools_window->dock_side(); | |
2194 ShowDevToolsContainer(); | |
2195 } else if (new_devtools_window) { | |
2196 UpdateDevToolsSplitPosition(); | |
2197 contents_split_->Layout(); | |
2198 } | |
2199 } | |
2200 | |
2201 void BrowserView::ShowDevToolsContainer() { | |
2202 if (!devtools_focus_tracker_.get()) { | |
2203 // Install devtools focus tracker when dev tools window is shown for the | 2155 // Install devtools focus tracker when dev tools window is shown for the |
2204 // first time. | 2156 // first time. |
2205 devtools_focus_tracker_.reset( | 2157 devtools_focus_tracker_.reset( |
2206 new views::ExternalFocusTracker(devtools_container_, | 2158 new views::ExternalFocusTracker(devtools_web_view_, |
2207 GetFocusManager())); | 2159 GetFocusManager())); |
2208 } | 2160 } |
2209 | 2161 |
2210 gfx::Size min_devtools_size(devtools_window_->GetMinimumWidth(), | 2162 // Restore focus to the last focused view when hiding devtools window. |
2211 devtools_window_->GetMinimumHeight()); | 2163 if (devtools_window_ && !new_devtools_window && |
2212 devtools_container_->SetPreferredSize(min_devtools_size); | 2164 devtools_focus_tracker_.get()) { |
| 2165 devtools_focus_tracker_->FocusLastFocusedExternalView(); |
| 2166 devtools_focus_tracker_.reset(); |
| 2167 } |
2213 | 2168 |
2214 devtools_container_->SetVisible(true); | 2169 devtools_window_ = new_devtools_window; |
2215 devtools_dock_side_ = devtools_window_->dock_side(); | 2170 if (devtools_window_) { |
2216 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT; | 2171 devtools_web_view_->SetPreferredSize(devtools_window_->GetMinimumSize()); |
2217 contents_split_->set_orientation( | 2172 devtools_web_view_->SetVisible(true); |
2218 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT | 2173 GetContentsLayoutManager()->SetContentsViewInsets( |
2219 : views::SingleSplitView::VERTICAL_SPLIT); | 2174 devtools_window_->GetContentsInsets()); |
2220 UpdateDevToolsSplitPosition(); | |
2221 contents_split_->InvalidateLayout(); | |
2222 Layout(); | |
2223 } | |
2224 | |
2225 void BrowserView::HideDevToolsContainer() { | |
2226 // Restore focus to the last focused view when hiding devtools window. | |
2227 devtools_focus_tracker_->FocusLastFocusedExternalView(); | |
2228 devtools_container_->SetVisible(false); | |
2229 contents_split_->InvalidateLayout(); | |
2230 Layout(); | |
2231 } | |
2232 | |
2233 void BrowserView::UpdateDevToolsSplitPosition() { | |
2234 contents_split_->set_resize_disabled( | |
2235 devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED); | |
2236 int split_size = contents_split_->GetDividerSize(); | |
2237 if (devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) { | |
2238 int split_offset = contents_split_->width() - split_size - | |
2239 devtools_window_->GetWidth(contents_split_->width()); | |
2240 contents_split_->set_divider_offset(split_offset); | |
2241 } else { | 2175 } else { |
2242 int height = devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_MINIMIZED ? | 2176 devtools_web_view_->SetVisible(false); |
2243 devtools_window_->GetMinimizedHeight() : | 2177 GetContentsLayoutManager()->SetContentsViewInsets(gfx::Insets()); |
2244 devtools_window_->GetHeight(contents_split_->height()); | |
2245 int split_offset = contents_split_->height() - split_size - height; | |
2246 contents_split_->set_divider_offset(split_offset); | |
2247 } | 2178 } |
| 2179 contents_container_->Layout(); |
2248 } | 2180 } |
2249 | 2181 |
2250 void BrowserView::UpdateUIForContents(WebContents* contents) { | 2182 void BrowserView::UpdateUIForContents(WebContents* contents) { |
2251 bool needs_layout = MaybeShowBookmarkBar(contents); | 2183 bool needs_layout = MaybeShowBookmarkBar(contents); |
2252 // TODO(jamescook): This function always returns true. Remove it and figure | 2184 // TODO(jamescook): This function always returns true. Remove it and figure |
2253 // out when layout is actually required. | 2185 // out when layout is actually required. |
2254 needs_layout |= MaybeShowInfoBar(contents); | 2186 needs_layout |= MaybeShowInfoBar(contents); |
2255 if (needs_layout) | 2187 if (needs_layout) |
2256 Layout(); | 2188 Layout(); |
2257 } | 2189 } |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { | 2600 !GetLocationBar()->GetOmniboxView()->model()->popup_model()->IsOpen()) { |
2669 gfx::Point icon_bottom( | 2601 gfx::Point icon_bottom( |
2670 toolbar_->location_bar()->GetLocationBarAnchorPoint()); | 2602 toolbar_->location_bar()->GetLocationBarAnchorPoint()); |
2671 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); | 2603 ConvertPointToTarget(toolbar_->location_bar(), this, &icon_bottom); |
2672 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); | 2604 gfx::Point infobar_top(0, infobar_container_->GetVerticalOverlap(NULL)); |
2673 ConvertPointToTarget(infobar_container_, this, &infobar_top); | 2605 ConvertPointToTarget(infobar_container_, this, &infobar_top); |
2674 top_arrow_height = infobar_top.y() - icon_bottom.y(); | 2606 top_arrow_height = infobar_top.y() - icon_bottom.y(); |
2675 } | 2607 } |
2676 return top_arrow_height; | 2608 return top_arrow_height; |
2677 } | 2609 } |
OLD | NEW |