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"
15 #include "xwalk/runtime/browser/ui/native_app_window.h"
16 #include "xwalk/runtime/browser/ui/native_app_window_tizen.h"
17 #include "xwalk/runtime/common/xwalk_common_messages.h"
19 #if defined(USE_OZONE)
20 #include "content/public/browser/render_view_host.h"
21 #include "ui/events/event.h"
22 #include "ui/events/event_constants.h"
23 #include "ui/events/keycodes/keyboard_codes_posix.h"
24 #include "ui/events/platform/platform_event_source.h"
25 #include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h"
28 #include "xwalk/application/common/application_manifest_constants.h"
32 namespace widget_keys = application_widget_keys;
34 namespace application {
36 ApplicationTizen::ApplicationTizen(
37 scoped_refptr<ApplicationData> data,
38 RuntimeContext* runtime_context,
39 Application::Observer* observer)
40 : Application(data, runtime_context, observer) {
41 #if defined(USE_OZONE)
42 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
46 ApplicationTizen::~ApplicationTizen() {
47 #if defined(USE_OZONE)
48 ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
52 void ApplicationTizen::Hide() {
53 DCHECK(!runtimes_.empty());
54 std::set<Runtime*>::iterator it = runtimes_.begin();
55 for (; it != runtimes_.end(); ++it) {
57 (*it)->window()->Hide();
61 bool ApplicationTizen::Launch(const LaunchParams& launch_params) {
62 if (Application::Launch(launch_params)) {
63 DCHECK(render_process_host_);
64 render_process_host_->GetScreenOrientationDispatcherHost()->
65 SetProviderForTests(this);
71 #if defined(USE_OZONE)
72 void ApplicationTizen::WillProcessEvent(const ui::PlatformEvent& event) {}
74 void ApplicationTizen::DidProcessEvent(
75 const ui::PlatformEvent& event) {
76 ui::Event* ui_event = static_cast<ui::Event*>(event);
77 if (!ui_event->IsKeyEvent() || ui_event->type() != ui::ET_KEY_PRESSED)
80 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event);
82 // FIXME: Most Wayland devices don't have similar hardware button for 'back'
83 // and 'memu' as Tizen Mobile, even that hardare buttons could be different
84 // across different kinds of Wayland platforms.
85 // Here use external keyboard button 'Backspace' & 'HOME' to emulate 'back'
86 // and 'menu' key. Should change this if there is customized key binding.
87 if (key_event->key_code() != ui::VKEY_BACK &&
88 key_event->key_code() != ui::VKEY_HOME)
91 TizenSettingInfo* info = static_cast<TizenSettingInfo*>(
92 data()->GetManifestData(widget_keys::kTizenSettingKey));
93 if (info && !info->hwkey_enabled())
96 for (std::set<xwalk::Runtime*>::iterator it = runtimes_.begin();
97 it != runtimes_.end(); ++it) {
98 (*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed(
99 (*it)->web_contents()->GetRoutingID(), key_event->key_code()));
104 void ApplicationTizen::LockOrientation(
105 blink::WebScreenOrientationLockType lock) {
106 DCHECK(!runtimes_.empty());
107 // FIXME: Probably need better alignment with
108 // https://w3c.github.io/screen-orientation/#screen-orientation-lock-lifetime
109 std::set<Runtime*>::iterator it = runtimes_.begin();
110 for (; it != runtimes_.end(); ++it) {
111 NativeAppWindow* window = (*it)->window();
112 if (window && window->IsActive()) {
113 ToNativeAppWindowTizen(window)->LockOrientation(lock);
119 void ApplicationTizen::UnlockOrientation() {
120 LockOrientation(blink::WebScreenOrientationLockDefault);
123 } // namespace application