OLD | NEW |
---|---|
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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 const char kOldPrefRight[] = "right"; | 73 const char kOldPrefRight[] = "right"; |
74 | 74 |
75 const char kPrefBottom[] = "dock_bottom"; | 75 const char kPrefBottom[] = "dock_bottom"; |
76 const char kPrefRight[] = "dock_right"; | 76 const char kPrefRight[] = "dock_right"; |
77 const char kPrefUndocked[] = "undocked"; | 77 const char kPrefUndocked[] = "undocked"; |
78 | 78 |
79 const char kDockSideBottom[] = "bottom"; | 79 const char kDockSideBottom[] = "bottom"; |
80 const char kDockSideRight[] = "right"; | 80 const char kDockSideRight[] = "right"; |
81 const char kDockSideUndocked[] = "undocked"; | 81 const char kDockSideUndocked[] = "undocked"; |
82 | 82 |
83 // Minimal height of devtools pane or content pane when devtools are docked | |
84 // to the browser window. | |
85 const int kMinDevToolsHeight = 50; | |
86 const int kMinDevToolsWidth = 150; | |
87 const int kMinContentsSize = 50; | |
88 | |
83 // static | 89 // static |
84 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { | 90 void DevToolsWindow::RegisterUserPrefs(PrefService* prefs) { |
85 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, | 91 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, |
86 true, | 92 true, |
87 PrefService::UNSYNCABLE_PREF); | 93 PrefService::UNSYNCABLE_PREF); |
88 prefs->RegisterStringPref(prefs::kDevToolsDockSide, | 94 prefs->RegisterStringPref(prefs::kDevToolsDockSide, |
89 kDockSideBottom, | 95 kDockSideBottom, |
90 PrefService::UNSYNCABLE_PREF); | 96 PrefService::UNSYNCABLE_PREF); |
91 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, | 97 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, |
92 PrefService::UNSYNCABLE_PREF); | 98 PrefService::UNSYNCABLE_PREF); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 DevToolsWindow::DevToolsWindow(TabContents* tab_contents, | 203 DevToolsWindow::DevToolsWindow(TabContents* tab_contents, |
198 Profile* profile, | 204 Profile* profile, |
199 RenderViewHost* inspected_rvh, | 205 RenderViewHost* inspected_rvh, |
200 DevToolsDockSide dock_side) | 206 DevToolsDockSide dock_side) |
201 : profile_(profile), | 207 : profile_(profile), |
202 inspected_tab_(NULL), | 208 inspected_tab_(NULL), |
203 tab_contents_(tab_contents), | 209 tab_contents_(tab_contents), |
204 browser_(NULL), | 210 browser_(NULL), |
205 dock_side_(dock_side), | 211 dock_side_(dock_side), |
206 is_loaded_(false), | 212 is_loaded_(false), |
207 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW) { | 213 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), |
214 width_(-1), | |
215 height_(-1) { | |
208 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost( | 216 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost( |
209 tab_contents->web_contents(), | 217 tab_contents->web_contents(), |
210 this); | 218 this); |
211 file_helper_.reset(new DevToolsFileHelper(profile, this)); | 219 file_helper_.reset(new DevToolsFileHelper(profile, this)); |
212 | 220 |
213 g_instances.Get().push_back(this); | 221 g_instances.Get().push_back(this); |
214 // Wipe out page icon so that the default application icon is used. | 222 // Wipe out page icon so that the default application icon is used. |
215 NavigationEntry* entry = | 223 NavigationEntry* entry = |
216 tab_contents_->web_contents()->GetController().GetActiveEntry(); | 224 tab_contents_->web_contents()->GetController().GetActiveEntry(); |
217 entry->GetFavicon().image = gfx::Image(); | 225 entry->GetFavicon().image = gfx::Image(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 CreateDevToolsBrowser(); | 322 CreateDevToolsBrowser(); |
315 | 323 |
316 if (should_show_window) { | 324 if (should_show_window) { |
317 browser_->window()->Show(); | 325 browser_->window()->Show(); |
318 tab_contents_->web_contents()->GetView()->SetInitialFocus(); | 326 tab_contents_->web_contents()->GetView()->SetInitialFocus(); |
319 } | 327 } |
320 | 328 |
321 ScheduleAction(action); | 329 ScheduleAction(action); |
322 } | 330 } |
323 | 331 |
332 int DevToolsWindow::GetWidth(int container_width) { | |
333 if (width_ == -1) { | |
334 width_ = profile_->GetPrefs()-> | |
335 GetInteger(prefs::kDevToolsVSplitLocation); | |
Peter Kasting
2012/10/26 19:35:41
Tiny nit: I'd linebreak after '(' instead of '->'
| |
336 } | |
337 | |
338 // By default, size devtools as 1/3 of the browser window. | |
339 if (width_ == -1) | |
340 width_ = container_width / 3; | |
341 | |
342 // Respect the minimum devtools width preset. | |
343 width_ = std::max(kMinDevToolsWidth, width_); | |
344 | |
345 // But it should never compromise the content window size unless the entire | |
346 // window is tiny. | |
347 width_ = std::min(container_width - kMinContentsSize, width_); | |
348 if (width_ < (kMinContentsSize / 2)) | |
349 width_ = container_width / 3; | |
350 return width_; | |
351 } | |
352 | |
353 int DevToolsWindow::GetHeight(int container_height) { | |
354 if (height_ == -1) { | |
355 height_ = profile_->GetPrefs()-> | |
356 GetInteger(prefs::kDevToolsHSplitLocation); | |
357 } | |
358 | |
359 // By default, size devtools as 1/3 of the browser window. | |
360 if (height_ == -1) | |
361 height_ = container_height / 3; | |
362 | |
363 // Respect the minimum devtools width preset. | |
364 height_ = std::max(kMinDevToolsHeight, height_); | |
365 | |
366 // But it should never compromise the content window size. | |
367 height_ = std::min(container_height - kMinContentsSize, height_); | |
368 if (height_ < (kMinContentsSize / 2)) | |
369 height_ = container_height / 3; | |
370 return height_; | |
371 } | |
372 | |
373 void DevToolsWindow::SetWidth(int width) { | |
374 width_ = width; | |
375 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); | |
376 } | |
377 | |
378 void DevToolsWindow::SetHeight(int height) { | |
379 height_ = height; | |
380 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height); | |
381 } | |
382 | |
324 RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 383 RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
325 return tab_contents_->web_contents()->GetRenderViewHost(); | 384 return tab_contents_->web_contents()->GetRenderViewHost(); |
326 } | 385 } |
327 | 386 |
328 void DevToolsWindow::CreateDevToolsBrowser() { | 387 void DevToolsWindow::CreateDevToolsBrowser() { |
329 // TODO(pfeldman): Make browser's getter for this key static. | 388 // TODO(pfeldman): Make browser's getter for this key static. |
330 std::string wp_key; | 389 std::string wp_key; |
331 wp_key.append(prefs::kBrowserWindowPlacement); | 390 wp_key.append(prefs::kBrowserWindowPlacement); |
332 wp_key.append("_"); | 391 wp_key.append("_"); |
333 wp_key.append(kDevToolsApp); | 392 wp_key.append(kDevToolsApp); |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 | 894 |
836 // static | 895 // static |
837 DevToolsDockSide DevToolsWindow::SideFromString( | 896 DevToolsDockSide DevToolsWindow::SideFromString( |
838 const std::string& dock_side) { | 897 const std::string& dock_side) { |
839 if (dock_side == kDockSideRight) | 898 if (dock_side == kDockSideRight) |
840 return DEVTOOLS_DOCK_SIDE_RIGHT; | 899 return DEVTOOLS_DOCK_SIDE_RIGHT; |
841 if (dock_side == kDockSideBottom) | 900 if (dock_side == kDockSideBottom) |
842 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 901 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
843 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 902 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
844 } | 903 } |
OLD | NEW |