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

Unified Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 10949023: Add switch to provide app window size on startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/startup/startup_browser_creator_impl.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
index 1e3a348a6c32b7373a583b2467ec101e0fcb84fb..77baf1c9c0582e2a04869b6caaae4e98296754f8 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
@@ -85,6 +85,11 @@
#include "grit/locale_settings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/screen.h"
+
+#if defined(USE_ASH)
+#include "ash/launcher/launcher_types.h"
+#endif
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
@@ -209,6 +214,26 @@ bool GetAppLaunchContainer(
return true;
}
+// Parse two comma-separated integers from str. Return true on success.
+bool ParseCommaSeparatedIntegers(const std::string& str,
+ int* ret_num1,
+ int* ret_num2) {
+ size_t num1_size = str.find_first_of(',');
sky 2012/09/19 17:20:14 Seems like this would be a lot simpler if you used
Nikita (slow) 2012/09/20 15:01:27 Done.
+ if (num1_size == std::string::npos)
+ return false;
+
+ size_t num2_pos = num1_size + 1;
+ size_t num2_size = str.size() - num2_pos;
+ int num1, num2;
+ if (!base::StringToInt(str.substr(0, num1_size), &num1) ||
+ !base::StringToInt(str.substr(num2_pos, num2_size), &num2))
+ return false;
+
+ *ret_num1 = num1;
+ *ret_num2 = num2;
+ return true;
+}
+
void RecordCmdLineAppHistogram() {
AppLauncherHandler::RecordAppLaunchType(
extension_misc::APP_LAUNCH_CMD_LINE_APP);
@@ -509,9 +534,33 @@ bool StartupBrowserCreatorImpl::OpenApplicationWindow(
extension_misc::APP_LAUNCH_CMD_LINE_APP_LEGACY);
}
+ gfx::Rect override_bounds;
+
+ if (command_line_.HasSwitch(switches::kAppWindowSize)) {
sky 2012/09/19 17:20:14 Move this into its own function.
Nikita (slow) 2012/09/20 15:01:27 Done.
+ int width, height;
+ std::string switch_value =
+ command_line_.GetSwitchValueASCII(switches::kAppWindowSize);
+ if (ParseCommaSeparatedIntegers(switch_value, &width, &height)) {
+ override_bounds.set_size(gfx::Size(width, height));
sky 2012/09/19 17:20:14 Make sure the size fits in the work area too.
Nikita (slow) 2012/09/20 15:01:27 Not sure if this is really needs to be done here a
Nikita (slow) 2012/09/20 15:01:27 Done.
+ const gfx::Rect work_area =
+ gfx::Screen::GetPrimaryDisplay().work_area();
+ override_bounds.set_x(
+ (work_area.width() - override_bounds.width()) / 2);
+ int extra_height_work_area = 0;
+#if defined(USE_ASH)
+ // In case of Ash we should center app window on the rest of the
+ // working area outside of launcher.
+ extra_height_work_area = ash::kLauncherPreferredSize;
sky 2012/09/19 17:20:14 The work area shouldn't include kLauncherPreferred
Nikita (slow) 2012/09/19 17:46:42 Probably you're right but from what I've seen on l
Nikita (slow) 2012/09/20 16:55:00 Removed for now. Work area should not include laun
+#endif
+ override_bounds.set_y((work_area.height() -
+ override_bounds.height() - extra_height_work_area) / 2);
+ }
+ }
+
WebContents* app_tab = application_launch::OpenAppShortcutWindow(
profile,
- url);
+ url,
+ override_bounds);
if (out_app_contents)
*out_app_contents = app_tab;

Powered by Google App Engine
This is Rietveld 408576698