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

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 11272015: DevTools: “Dock to right” broken after turning a tab into a window of its own. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: GTK comments addressed, docs updated. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 using views::ColumnSet; 154 using views::ColumnSet;
155 using views::GridLayout; 155 using views::GridLayout;
156 156
157 namespace { 157 namespace {
158 // The height of the status bubble. 158 // The height of the status bubble.
159 const int kStatusBubbleHeight = 20; 159 const int kStatusBubbleHeight = 20;
160 // The name of a key to store on the window handle so that other code can 160 // The name of a key to store on the window handle so that other code can
161 // locate this object using just the handle. 161 // locate this object using just the handle.
162 const char* const kBrowserViewKey = "__BROWSER_VIEW__"; 162 const char* const kBrowserViewKey = "__BROWSER_VIEW__";
163 163
164 // Minimal height of devtools pane or content pane when devtools are docked
165 // to the browser window.
166 const int kMinDevToolsHeight = 50;
167 const int kMinDevToolsWidth = 150;
168 const int kMinContentsSize = 50;
169
170 // The number of milliseconds between loading animation frames. 164 // The number of milliseconds between loading animation frames.
171 const int kLoadingAnimationFrameTimeMs = 30; 165 const int kLoadingAnimationFrameTimeMs = 30;
172 // The amount of space we expect the window border to take up. 166 // The amount of space we expect the window border to take up.
173 const int kWindowBorderWidth = 5; 167 const int kWindowBorderWidth = 5;
174 168
175 // How round the 'new tab' style bookmarks bar is. 169 // How round the 'new tab' style bookmarks bar is.
176 const int kNewtabBarRoundness = 5; 170 const int kNewtabBarRoundness = 5;
177 171
178 } // namespace 172 } // namespace
179 173
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 active_bookmark_bar_(NULL), 349 active_bookmark_bar_(NULL),
356 tabstrip_(NULL), 350 tabstrip_(NULL),
357 toolbar_(NULL), 351 toolbar_(NULL),
358 window_switcher_button_(NULL), 352 window_switcher_button_(NULL),
359 infobar_container_(NULL), 353 infobar_container_(NULL),
360 contents_container_(NULL), 354 contents_container_(NULL),
361 devtools_container_(NULL), 355 devtools_container_(NULL),
362 contents_(NULL), 356 contents_(NULL),
363 contents_split_(NULL), 357 contents_split_(NULL),
364 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM), 358 devtools_dock_side_(DEVTOOLS_DOCK_SIDE_BOTTOM),
359 devtools_window_(NULL),
365 initialized_(false), 360 initialized_(false),
366 ignore_layout_(true), 361 ignore_layout_(true),
367 #if defined(OS_WIN) && !defined(USE_AURA) 362 #if defined(OS_WIN) && !defined(USE_AURA)
368 hung_window_detector_(&hung_plugin_action_), 363 hung_window_detector_(&hung_plugin_action_),
369 ticker_(0), 364 ticker_(0),
370 #endif 365 #endif
371 force_location_bar_focus_(false), 366 force_location_bar_focus_(false),
372 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)), 367 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)),
373 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) { 368 ALLOW_THIS_IN_INITIALIZER_LIST(activate_modal_dialog_factory_(this)) {
374 browser_->tab_strip_model()->AddObserver(this); 369 browser_->tab_strip_model()->AddObserver(this);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 if (MaybeShowBookmarkBar(GetActiveTabContents())) 690 if (MaybeShowBookmarkBar(GetActiveTabContents()))
696 Layout(); 691 Layout();
697 } 692 }
698 693
699 void BrowserView::UpdateDevTools() { 694 void BrowserView::UpdateDevTools() {
700 UpdateDevToolsForContents(GetActiveTabContents()); 695 UpdateDevToolsForContents(GetActiveTabContents());
701 Layout(); 696 Layout();
702 } 697 }
703 698
704 699
705 void BrowserView::SetDevToolsDockSide(DevToolsDockSide side) {
706 if (devtools_dock_side_ == side)
707 return;
708
709 if (devtools_container_->visible()) {
710 HideDevToolsContainer();
711 ShowDevToolsContainer(side);
712 } else {
713 devtools_dock_side_ = side;
714 }
715 }
716
717 void BrowserView::UpdateLoadingAnimations(bool should_animate) { 700 void BrowserView::UpdateLoadingAnimations(bool should_animate) {
718 if (should_animate) { 701 if (should_animate) {
719 if (!loading_animation_timer_.IsRunning()) { 702 if (!loading_animation_timer_.IsRunning()) {
720 // Loads are happening, and the timer isn't running, so start it. 703 // Loads are happening, and the timer isn't running, so start it.
721 last_animation_time_ = base::TimeTicks::Now(); 704 last_animation_time_ = base::TimeTicks::Now();
722 loading_animation_timer_.Start(FROM_HERE, 705 loading_animation_timer_.Start(FROM_HERE,
723 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, 706 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this,
724 &BrowserView::LoadingAnimationCallback); 707 &BrowserView::LoadingAnimationCallback);
725 } 708 }
726 } else { 709 } else {
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 } 2053 }
2071 2054
2072 bool BrowserView::MaybeShowInfoBar(TabContents* contents) { 2055 bool BrowserView::MaybeShowInfoBar(TabContents* contents) {
2073 // TODO(beng): Remove this function once the interface between 2056 // TODO(beng): Remove this function once the interface between
2074 // InfoBarContainer, DownloadShelfView and WebContents and this 2057 // InfoBarContainer, DownloadShelfView and WebContents and this
2075 // view is sorted out. 2058 // view is sorted out.
2076 return true; 2059 return true;
2077 } 2060 }
2078 2061
2079 void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) { 2062 void BrowserView::UpdateDevToolsForContents(TabContents* tab_contents) {
2080 DevToolsWindow* devtools_window = tab_contents ? 2063 DevToolsWindow* new_devtools_window = tab_contents ?
2081 DevToolsWindow::GetDockedInstanceForInspectedTab( 2064 DevToolsWindow::GetDockedInstanceForInspectedTab(
2082 tab_contents->web_contents()) : NULL; 2065 tab_contents->web_contents()) : NULL;
2083 TabContents* devtools_tab_contents = 2066 // Fast return in case of the same window having same orientation.
2084 devtools_window ? devtools_window->tab_contents() : NULL; 2067 if (devtools_window_ == new_devtools_window) {
2085 WebContents* devtools_contents = devtools_tab_contents ? 2068 if (!new_devtools_window ||
2086 devtools_tab_contents->web_contents() : NULL; 2069 (new_devtools_window->dock_side() == devtools_dock_side_)) {
2087 2070 return;
2088 if (devtools_contents == devtools_container_->web_contents()) { 2071 }
2089 if (devtools_contents &&
2090 devtools_window->dock_side() != devtools_dock_side_)
2091 SetDevToolsDockSide(devtools_window->dock_side());
2092 return;
2093 } 2072 }
2094 2073
2095 bool should_show = devtools_contents && !devtools_container_->visible(); 2074 // Replace tab contents.
2096 bool should_hide = !devtools_contents && devtools_container_->visible(); 2075 if (devtools_window_ != new_devtools_window) {
2076 devtools_container_->SetWebContents(new_devtools_window ?
2077 new_devtools_window->tab_contents()->web_contents() : NULL);
2078 }
2097 2079
2098 devtools_container_->SetWebContents(devtools_contents); 2080 // Store last used position.
2099 RestackLocationBarContainer(); 2081 if (devtools_window_) {
2082 if (devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT) {
2083 devtools_window_->SetWidth(
2084 contents_split_->width() - contents_split_->divider_offset());
Peter Kasting 2012/10/26 19:35:41 The reason I said DevToolsWindow doesn't need widt
pfeldman 2012/10/29 12:24:25 The problem is that there is 1 browser_view instan
Peter Kasting 2012/10/29 20:30:50 OK, I finally figured out what was confusing me.
2085 } else {
2086 devtools_window_->SetHeight(
2087 contents_split_->height() - contents_split_->divider_offset());
2088 }
2089 }
2100 2090
2101 if (should_show) 2091 // Show / hide container if necessary. Changing dock orientation is
2102 ShowDevToolsContainer(devtools_window->dock_side()); 2092 // hide + show.
2103 else if (should_hide) 2093 bool should_hide = devtools_window_ && (!new_devtools_window ||
2094 devtools_dock_side_ != new_devtools_window->dock_side());
2095 bool should_show = new_devtools_window && (!devtools_window_ || should_hide);
2096
2097 if (should_hide)
2104 HideDevToolsContainer(); 2098 HideDevToolsContainer();
2099
2100 devtools_window_ = new_devtools_window;
2101
2102 if (should_show) {
2103 devtools_dock_side_ = new_devtools_window->dock_side();
2104 ShowDevToolsContainer();
2105 } else if (new_devtools_window) {
2106 UpdateDevToolsSplitPosition();
2107 }
2105 } 2108 }
2106 2109
2107 void BrowserView::ShowDevToolsContainer(DevToolsDockSide dock_side) { 2110 void BrowserView::ShowDevToolsContainer() {
2108 devtools_dock_side_ = dock_side;
2109 if (!devtools_focus_tracker_.get()) { 2111 if (!devtools_focus_tracker_.get()) {
2110 // Install devtools focus tracker when dev tools window is shown for the 2112 // Install devtools focus tracker when dev tools window is shown for the
2111 // first time. 2113 // first time.
2112 devtools_focus_tracker_.reset( 2114 devtools_focus_tracker_.reset(
2113 new views::ExternalFocusTracker(devtools_container_, 2115 new views::ExternalFocusTracker(devtools_container_,
2114 GetFocusManager())); 2116 GetFocusManager()));
2115 } 2117 }
2116 2118 devtools_container_->SetVisible(true);
2119 devtools_dock_side_ = devtools_window_->dock_side();
2117 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT; 2120 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT;
2118
2119 int contents_size = dock_to_right ? contents_split_->width() :
2120 contents_split_->height();
2121 int min_size = dock_to_right ? kMinDevToolsWidth : kMinDevToolsHeight;
2122
2123 // Restore split offset.
2124 int split_offset = browser_->profile()->GetPrefs()->
2125 GetInteger(dock_to_right ? prefs::kDevToolsVSplitLocation :
2126 prefs::kDevToolsHSplitLocation);
2127
2128 if (split_offset == -1)
2129 split_offset = contents_size * 1 / 3;
2130
2131 // Make sure user can see both panes.
2132 split_offset = std::max(min_size, split_offset);
2133 split_offset = std::min(contents_size - kMinContentsSize, split_offset);
2134 if (split_offset < 0)
2135 split_offset = contents_size * 1 / 3;
2136 contents_split_->set_divider_offset(contents_size - split_offset);
2137
2138 devtools_container_->SetVisible(true);
2139 contents_split_->set_orientation( 2121 contents_split_->set_orientation(
2140 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT 2122 dock_to_right ? views::SingleSplitView::HORIZONTAL_SPLIT
2141 : views::SingleSplitView::VERTICAL_SPLIT); 2123 : views::SingleSplitView::VERTICAL_SPLIT);
2124 UpdateDevToolsSplitPosition();
2142 contents_split_->InvalidateLayout(); 2125 contents_split_->InvalidateLayout();
2143 Layout(); 2126 Layout();
2144 // In NTP search mode, schedule a repaint of toolbar and tabstrip. 2127 // In NTP search mode, schedule a repaint of toolbar and tabstrip.
2145 if (browser()->search_model()->mode().is_ntp()) { 2128 if (browser()->search_model()->mode().is_ntp()) {
2146 toolbar_->SchedulePaint(); 2129 toolbar_->SchedulePaint();
2147 tabstrip_->SchedulePaint(); 2130 tabstrip_->SchedulePaint();
2148 } 2131 }
2149 } 2132 }
2150 2133
2151 void BrowserView::HideDevToolsContainer() { 2134 void BrowserView::HideDevToolsContainer() {
2152 // Store split offset when hiding devtools window only.
2153 bool dock_to_right = devtools_dock_side_ == DEVTOOLS_DOCK_SIDE_RIGHT;
2154 int contents_size = dock_to_right ? contents_split_->width() :
2155 contents_split_->height();
2156
2157 browser_->profile()->GetPrefs()->SetInteger(
2158 dock_to_right ? prefs::kDevToolsVSplitLocation :
2159 prefs::kDevToolsHSplitLocation,
2160 contents_size - contents_split_->divider_offset());
2161
2162 // Restore focus to the last focused view when hiding devtools window. 2135 // Restore focus to the last focused view when hiding devtools window.
2163 devtools_focus_tracker_->FocusLastFocusedExternalView(); 2136 devtools_focus_tracker_->FocusLastFocusedExternalView();
2164
2165 devtools_container_->SetVisible(false); 2137 devtools_container_->SetVisible(false);
2166 contents_split_->InvalidateLayout(); 2138 contents_split_->InvalidateLayout();
2167 Layout(); 2139 Layout();
2168 // In NTP search mode, schedule a repaint of toolbar and tabstrip. 2140 // In NTP search mode, schedule a repaint of toolbar and tabstrip.
2169 if (browser()->search_model()->mode().is_ntp()) { 2141 if (browser()->search_model()->mode().is_ntp()) {
2170 toolbar_->SchedulePaint(); 2142 toolbar_->SchedulePaint();
2171 tabstrip_->SchedulePaint(); 2143 tabstrip_->SchedulePaint();
2172 } 2144 }
2173 } 2145 }
2174 2146
2147 void BrowserView::UpdateDevToolsSplitPosition() {
2148 if (devtools_window_->dock_side() == DEVTOOLS_DOCK_SIDE_RIGHT) {
2149 int split_offset = contents_split_->width() -
2150 devtools_window_->GetWidth(contents_split_->width());
2151 contents_split_->set_divider_offset(split_offset);
2152 } else {
2153 int split_offset = contents_split_->height() -
2154 devtools_window_->GetHeight(contents_split_->height());
2155 contents_split_->set_divider_offset(split_offset);
2156 }
2157 }
2158
2175 void BrowserView::UpdateUIForContents(TabContents* contents) { 2159 void BrowserView::UpdateUIForContents(TabContents* contents) {
2176 bool needs_layout = MaybeShowBookmarkBar(contents); 2160 bool needs_layout = MaybeShowBookmarkBar(contents);
2177 needs_layout |= MaybeShowInfoBar(contents); 2161 needs_layout |= MaybeShowInfoBar(contents);
2178 if (needs_layout) 2162 if (needs_layout)
2179 Layout(); 2163 Layout();
2180 } 2164 }
2181 2165
2182 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view, 2166 bool BrowserView::UpdateChildViewAndLayout(views::View* new_view,
2183 views::View** old_view) { 2167 views::View** old_view) {
2184 DCHECK(old_view); 2168 DCHECK(old_view);
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
2670 2654
2671 Browser* modal_browser = 2655 Browser* modal_browser =
2672 browser::FindBrowserWithWebContents(active_dialog->web_contents()); 2656 browser::FindBrowserWithWebContents(active_dialog->web_contents());
2673 if (modal_browser && (browser_ != modal_browser)) { 2657 if (modal_browser && (browser_ != modal_browser)) {
2674 modal_browser->window()->FlashFrame(true); 2658 modal_browser->window()->FlashFrame(true);
2675 modal_browser->window()->Activate(); 2659 modal_browser->window()->Activate();
2676 } 2660 }
2677 2661
2678 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); 2662 AppModalDialogQueue::GetInstance()->ActivateModalDialog();
2679 } 2663 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698