1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "xwalk/runtime/browser/runtime_ui_delegate.h"
7 #include "base/command_line.h"
8 #include "grit/xwalk_resources.h"
9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/image/image.h"
11 #include "xwalk/runtime/browser/image_util.h"
12 #include "xwalk/runtime/browser/runtime.h"
13 #include "xwalk/runtime/common/xwalk_switches.h"
16 // FIXME : Need to figure out what code paths are used by Android and not
17 // compile the unneeded files.
18 #if !defined(OS_ANDROID)
20 // The default size for web content area size.
21 const int kDefaultWidth = 840;
22 const int kDefaultHeight = 600;
24 NativeAppWindow* CreateWindow(
25 Runtime* runtime, const NativeAppWindow::CreateParams& params) {
26 NativeAppWindow* window = NativeAppWindow::Create(params);
27 // FIXME : Pass an App icon in params.
28 // Set the app icon if it is passed from command line.
29 CommandLine* command_line = CommandLine::ForCurrentProcess();
31 if (command_line->HasSwitch(switches::kAppIcon)) {
32 base::FilePath icon_file =
33 command_line->GetSwitchValuePath(switches::kAppIcon);
34 app_icon = xwalk_utils::LoadImageFromFilePath(icon_file);
36 // Otherwise, use the default icon for Crosswalk app.
37 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
38 app_icon = rb.GetNativeImageNamed(IDR_XWALK_ICON_48);
41 window->UpdateIcon(app_icon);
43 unsigned int fullscreen_options = runtime->fullscreen_options();
44 if (params.state == ui::SHOW_STATE_FULLSCREEN)
45 fullscreen_options |= Runtime::FULLSCREEN_FOR_LAUNCH;
47 fullscreen_options &= ~Runtime::FULLSCREEN_FOR_LAUNCH;
48 runtime->set_fullscreen_options(fullscreen_options);
56 RuntimeUIDelegate* DefaultRuntimeUIDelegate::Create(
57 Runtime* runtime, const NativeAppWindow::CreateParams& params) {
58 return new DefaultRuntimeUIDelegate(runtime, params);
61 DefaultRuntimeUIDelegate::DefaultRuntimeUIDelegate(
62 Runtime* runtime, const NativeAppWindow::CreateParams& params)
64 window_params_(params),
69 DefaultRuntimeUIDelegate::~DefaultRuntimeUIDelegate() {
72 void DefaultRuntimeUIDelegate::Show() {
73 #if !defined(OS_ANDROID)
75 if (window_params_.bounds.IsEmpty())
76 window_params_.bounds = gfx::Rect(0, 0, kDefaultWidth, kDefaultHeight);
77 window_params_.delegate = this;
78 window_params_.web_contents = runtime_->web_contents();
79 window_ = CreateWindow(runtime_, window_params_);
87 void DefaultRuntimeUIDelegate::UpdateTitle(const base::string16& text) {
89 window_->UpdateTitle(text);
92 void DefaultRuntimeUIDelegate::UpdateIcon(const gfx::Image& image) {
94 window_->UpdateIcon(image);
97 void DefaultRuntimeUIDelegate::SetFullscreen(bool enter_fullscreen) {
99 window_->SetFullscreen(enter_fullscreen);
102 void DefaultRuntimeUIDelegate::Close() {
107 void DefaultRuntimeUIDelegate::DeleteDelegate() {
116 void DefaultRuntimeUIDelegate::OnWindowDestroyed() {