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