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 devotools 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 // Called only for the case when devtools window is docked to the side. | |
yurys
2012/10/25 15:35:24
I'd rather move the comment to the method declarat
pfeldman
2012/10/25 16:14:42
Done.
| |
334 if (width_ == -1) { | |
335 width_ = profile_->GetPrefs()-> | |
336 GetInteger(prefs::kDevToolsVSplitLocation); | |
337 } | |
338 | |
339 // By default, size devtools as 1/3 of the browser window. | |
340 if (width_ == -1) | |
341 width_ = container_width / 3; | |
342 | |
343 // Respect the minimum devtools width preset. | |
344 width_ = std::max(kMinDevToolsWidth, width_); | |
345 | |
346 // But it should never compromise the content window size. | |
347 width_ = std::min(container_width - kMinContentsSize, width_); | |
348 if (width_ < 0) | |
349 width_ = container_width / 3; | |
350 return width_; | |
351 } | |
352 | |
353 int DevToolsWindow::GetHeight(int container_height) { | |
354 // Called only for the case when devtools window is docked to bottom. | |
yurys
2012/10/25 15:35:24
ditto
pfeldman
2012/10/25 16:14:42
Done.
| |
355 if (height_ == -1) { | |
356 height_ = profile_->GetPrefs()-> | |
357 GetInteger(prefs::kDevToolsHSplitLocation); | |
358 } | |
359 | |
360 // By default, size devtools as 1/3 of the browser window. | |
361 if (height_ == -1) | |
362 height_ = container_height * 1 / 3; | |
363 | |
364 // Respect the minimum devtools width preset. | |
365 height_ = std::max(kMinDevToolsHeight, height_); | |
366 | |
367 // But it should never compromise the content window size. | |
368 height_ = std::min(container_height - kMinContentsSize, height_); | |
369 if (height_ < 0) | |
370 height_ = container_height * 1 / 3; | |
371 return height_; | |
372 } | |
373 | |
374 void DevToolsWindow::SetWidth(int width) { | |
375 width_ = width; | |
376 profile_->GetPrefs()->SetInteger(prefs::kDevToolsVSplitLocation, width); | |
377 } | |
378 | |
379 void DevToolsWindow::SetHeight(int height) { | |
380 height_ = height; | |
381 profile_->GetPrefs()->SetInteger(prefs::kDevToolsHSplitLocation, height); | |
382 } | |
383 | |
324 RenderViewHost* DevToolsWindow::GetRenderViewHost() { | 384 RenderViewHost* DevToolsWindow::GetRenderViewHost() { |
325 return tab_contents_->web_contents()->GetRenderViewHost(); | 385 return tab_contents_->web_contents()->GetRenderViewHost(); |
326 } | 386 } |
327 | 387 |
328 void DevToolsWindow::CreateDevToolsBrowser() { | 388 void DevToolsWindow::CreateDevToolsBrowser() { |
329 // TODO(pfeldman): Make browser's getter for this key static. | 389 // TODO(pfeldman): Make browser's getter for this key static. |
330 std::string wp_key; | 390 std::string wp_key; |
331 wp_key.append(prefs::kBrowserWindowPlacement); | 391 wp_key.append(prefs::kBrowserWindowPlacement); |
332 wp_key.append("_"); | 392 wp_key.append("_"); |
333 wp_key.append(kDevToolsApp); | 393 wp_key.append(kDevToolsApp); |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 | 895 |
836 // static | 896 // static |
837 DevToolsDockSide DevToolsWindow::SideFromString( | 897 DevToolsDockSide DevToolsWindow::SideFromString( |
838 const std::string& dock_side) { | 898 const std::string& dock_side) { |
839 if (dock_side == kDockSideRight) | 899 if (dock_side == kDockSideRight) |
840 return DEVTOOLS_DOCK_SIDE_RIGHT; | 900 return DEVTOOLS_DOCK_SIDE_RIGHT; |
841 if (dock_side == kDockSideBottom) | 901 if (dock_side == kDockSideBottom) |
842 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 902 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
843 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 903 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
844 } | 904 } |
OLD | NEW |