1 // Copyright (c) 2013 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/application/browser/application_tizen.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
14 #include "content/browser/screen_orientation/screen_orientation_provider.h"
16 #include "xwalk/runtime/browser/ui/native_app_window.h"
17 #include "xwalk/runtime/browser/ui/native_app_window_tizen.h"
18 #include "xwalk/runtime/common/xwalk_common_messages.h"
20 #if defined(USE_OZONE)
21 #include "content/public/browser/render_view_host.h"
22 #include "ui/events/event.h"
23 #include "ui/events/event_constants.h"
24 #include "ui/events/keycodes/keyboard_codes_posix.h"
25 #include "ui/events/platform/platform_event_source.h"
26 #include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h"
29 #include "xwalk/application/common/application_manifest_constants.h"
33 namespace widget_keys = application_widget_keys;
35 namespace application {
37 class ScreenOrientationProviderTizen :
38 public content::ScreenOrientationProvider {
40 explicit ScreenOrientationProviderTizen(const base::WeakPtr<Application>& app)
44 virtual void LockOrientation(
45 blink::WebScreenOrientationLockType lock) OVERRIDE {
48 const std::set<Runtime*>& runtimes = app_->runtimes();
49 DCHECK(!runtimes.empty());
50 // FIXME: Probably need better alignment with
51 // https://w3c.github.io/screen-orientation/#screen-orientation-lock-lifetime
52 std::set<Runtime*>::iterator it = runtimes.begin();
53 for (; it != runtimes.end(); ++it) {
54 NativeAppWindow* window = (*it)->window();
55 if (window && window->IsActive()) {
56 ToNativeAppWindowTizen(window)->LockOrientation(lock);
62 virtual void UnlockOrientation() OVERRIDE {
63 LockOrientation(blink::WebScreenOrientationLockDefault);
67 base::WeakPtr<Application> app_;
70 ApplicationTizen::ApplicationTizen(
71 scoped_refptr<ApplicationData> data,
72 RuntimeContext* runtime_context,
73 Application::Observer* observer)
74 : Application(data, runtime_context, observer) {
75 #if defined(USE_OZONE)
76 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
80 ApplicationTizen::~ApplicationTizen() {
81 #if defined(USE_OZONE)
82 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
86 void ApplicationTizen::Hide() {
87 DCHECK(!runtimes_.empty());
88 std::set<Runtime*>::iterator it = runtimes_.begin();
89 for (; it != runtimes_.end(); ++it) {
91 (*it)->window()->Hide();
95 bool ApplicationTizen::Launch(const LaunchParams& launch_params) {
96 if (Application::Launch(launch_params)) {
97 DCHECK(render_process_host_);
98 render_process_host_->GetScreenOrientationDispatcherHost()->
99 SetProviderForTests(new ScreenOrientationProviderTizen(GetWeakPtr()));
105 #if defined(USE_OZONE)
106 void ApplicationTizen::WillProcessEvent(const ui::PlatformEvent& event) {}
108 void ApplicationTizen::DidProcessEvent(
109 const ui::PlatformEvent& event) {
110 ui::Event* ui_event = static_cast<ui::Event*>(event);
111 if (!ui_event->IsKeyEvent() || ui_event->type() != ui::ET_KEY_PRESSED)
114 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event);
116 // FIXME: Most Wayland devices don't have similar hardware button for 'back'
117 // and 'memu' as Tizen Mobile, even that hardare buttons could be different
118 // across different kinds of Wayland platforms.
119 // Here use external keyboard button 'Backspace' & 'HOME' to emulate 'back'
120 // and 'menu' key. Should change this if there is customized key binding.
121 if (key_event->key_code() != ui::VKEY_BACK &&
122 key_event->key_code() != ui::VKEY_HOME)
125 TizenSettingInfo* info = static_cast<TizenSettingInfo*>(
126 data()->GetManifestData(widget_keys::kTizenSettingKey));
127 if (info && !info->hwkey_enabled())
130 for (std::set<xwalk::Runtime*>::iterator it = runtimes_.begin();
131 it != runtimes_.end(); ++it) {
132 (*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
133 (*it)->web_contents()->GetRoutingID(), key_event->key_code()));
138 } // namespace application