Chromium Code Reviews| 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 "chrome/browser/ui/browser_window_state.h" | 5 #include "chrome/browser/ui/browser_window_state.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/defaults.h" | 9 #include "chrome/browser/defaults.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 // Save to the session storage service, used when reloading a past session. | 73 // Save to the session storage service, used when reloading a past session. |
| 74 // Note that we don't want to be the ones who cause lazy initialization of | 74 // Note that we don't want to be the ones who cause lazy initialization of |
| 75 // the session service. This function gets called during initial window | 75 // the session service. This function gets called during initial window |
| 76 // showing, and we don't want to bring in the session service this early. | 76 // showing, and we don't want to bring in the session service this early. |
| 77 SessionService* session_service = | 77 SessionService* session_service = |
| 78 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); | 78 SessionServiceFactory::GetForProfileIfExisting(browser->profile()); |
| 79 if (session_service) | 79 if (session_service) |
| 80 session_service->SetWindowBounds(browser->session_id(), bounds, show_state); | 80 session_service->SetWindowBounds(browser->session_id(), bounds, show_state); |
| 81 } | 81 } |
| 82 | 82 |
| 83 gfx::Rect GetSavedWindowBounds(const Browser* browser) { | 83 void GetSavedWindowBoundsAndShowState(const Browser* browser, |
| 84 gfx::Rect restored_bounds = browser->override_bounds(); | 84 gfx::Rect* bounds, |
| 85 WindowSizer::GetBrowserWindowBounds(browser->app_name(), | 85 ui::WindowShowState* show_state) { |
| 86 restored_bounds, | 86 DCHECK(bounds); |
|
sky
2012/10/08 21:01:25
If you're going to add DCHECKs, you should DCHECK
Mr4D (OOO till 08-26)
2012/10/08 23:04:27
Done.
| |
| 87 browser, | 87 DCHECK(show_state); |
| 88 &restored_bounds); | 88 *bounds = browser->override_bounds(); |
| 89 WindowSizer::GetBrowserWindowBoundsAndShowState(browser->app_name(), | |
| 90 *bounds, | |
| 91 browser, | |
| 92 bounds, | |
| 93 show_state); | |
| 89 | 94 |
| 90 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 95 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 91 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); | 96 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); |
| 92 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); | 97 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); |
| 93 if (record_mode || playback_mode) { | 98 if (record_mode || playback_mode) { |
| 94 // In playback/record mode we always fix the size of the browser and | 99 // In playback/record mode we always fix the size of the browser and |
| 95 // move it to (0,0). The reason for this is two reasons: First we want | 100 // move it to (0,0). The reason for this is two reasons: First we want |
| 96 // resize/moves in the playback to still work, and Second we want | 101 // resize/moves in the playback to still work, and Second we want |
| 97 // playbacks to work (as much as possible) on machines w/ different | 102 // playbacks to work (as much as possible) on machines w/ different |
| 98 // screen sizes. | 103 // screen sizes. |
| 99 restored_bounds = gfx::Rect(0, 0, 800, 600); | 104 *bounds = gfx::Rect(0, 0, 800, 600); |
| 100 } | 105 } |
| 101 | 106 |
| 102 // The following options override playback/record. | 107 // The following options override playback/record. |
| 103 if (parsed_command_line.HasSwitch(switches::kWindowSize)) { | 108 if (parsed_command_line.HasSwitch(switches::kWindowSize)) { |
| 104 std::string str = | 109 std::string str = |
| 105 parsed_command_line.GetSwitchValueASCII(switches::kWindowSize); | 110 parsed_command_line.GetSwitchValueASCII(switches::kWindowSize); |
| 106 int width, height; | 111 int width, height; |
| 107 if (ParseCommaSeparatedIntegers(str, &width, &height)) | 112 if (ParseCommaSeparatedIntegers(str, &width, &height)) |
| 108 restored_bounds.set_size(gfx::Size(width, height)); | 113 bounds->set_size(gfx::Size(width, height)); |
| 109 } | 114 } |
| 110 if (parsed_command_line.HasSwitch(switches::kWindowPosition)) { | 115 if (parsed_command_line.HasSwitch(switches::kWindowPosition)) { |
| 111 std::string str = | 116 std::string str = |
| 112 parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition); | 117 parsed_command_line.GetSwitchValueASCII(switches::kWindowPosition); |
| 113 int x, y; | 118 int x, y; |
| 114 if (ParseCommaSeparatedIntegers(str, &x, &y)) | 119 if (ParseCommaSeparatedIntegers(str, &x, &y)) |
| 115 restored_bounds.set_origin(gfx::Point(x, y)); | 120 bounds->set_origin(gfx::Point(x, y)); |
| 116 } | 121 } |
| 117 | |
| 118 return restored_bounds; | |
| 119 } | |
| 120 | |
| 121 ui::WindowShowState GetSavedWindowShowState(const Browser* browser) { | |
| 122 // Only tabbed browsers use the command line or preference state, with the | |
| 123 // exception of devtools. | |
| 124 bool show_state = !browser->is_type_tabbed() && !browser->is_devtools(); | |
| 125 | |
| 126 #if defined(USE_AURA) | |
| 127 // Apps save state on aura. | |
| 128 show_state &= !browser->is_app(); | |
| 129 #endif | |
| 130 | |
| 131 if (show_state) | |
| 132 return browser->initial_show_state(); | |
| 133 | |
| 134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kStartMaximized)) | |
| 135 return ui::SHOW_STATE_MAXIMIZED; | |
| 136 | |
| 137 if (browser->initial_show_state() != ui::SHOW_STATE_DEFAULT) | |
| 138 return browser->initial_show_state(); | |
| 139 | |
| 140 const DictionaryValue* window_pref = browser->profile()->GetPrefs()-> | |
| 141 GetDictionary(GetWindowPlacementKey(browser).c_str()); | |
| 142 bool maximized = false; | |
| 143 window_pref->GetBoolean("maximized", &maximized); | |
| 144 | |
| 145 return maximized ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_DEFAULT; | |
| 146 } | 122 } |
| 147 | 123 |
| 148 } // namespace chrome | 124 } // namespace chrome |
| OLD | NEW |