Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / xwalk / tizen / mobile / ui / tizen_system_indicator.cc
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.
4
5 #include "xwalk/tizen/mobile/ui/tizen_system_indicator.h"
6
7 #include "ui/gfx/canvas.h"
8 #include "xwalk/tizen/mobile/ui/tizen_system_indicator_watcher.h"
9
10 #include "ui/views/background.h"
11 #include "ui/views/widget/native_widget.h"
12 #include "ui/views/widget/root_view.h"
13 #include "ui/aura/root_window.h"
14
15 namespace {
16
17 SkColor kBGColor = SkColorSetARGB(255, 52, 52, 50);
18
19 }  // namespace
20
21 namespace xwalk {
22
23 TizenSystemIndicator::TizenSystemIndicator()
24   : watcher_(NULL) {
25   set_background(views::Background::CreateSolidBackground(kBGColor));
26 }
27
28 TizenSystemIndicator::~TizenSystemIndicator() {
29 }
30
31 bool TizenSystemIndicator::IsConnected() const {
32   return watcher_;
33 }
34
35 void TizenSystemIndicator::SetWatcher(TizenSystemIndicatorWatcher* watcher) {
36   watcher_ = watcher;
37 }
38
39 gfx::Size TizenSystemIndicator::GetPreferredSize() {
40   // The size must be in DIPs. SkiaImage handles that and null images.
41   return GetImage().size();
42 }
43
44 bool TizenSystemIndicator::OnMousePressed(const ui::MouseEvent& event) {
45   if (!IsConnected())
46     return false;
47   const gfx::Point position = event.location();
48   watcher_->OnMouseDown(position.x(), position.y());
49   return true;
50 }
51
52 void TizenSystemIndicator::OnMouseReleased(const ui::MouseEvent& event) {
53   if (IsConnected())
54     watcher_->OnMouseUp();
55 }
56
57 void TizenSystemIndicator::OnGestureEvent(ui::GestureEvent* event) {
58   if (!IsConnected())
59     return;
60
61   const gfx::Point position = event->location();
62
63   switch (event->type()) {
64     case ui::ET_UNKNOWN:
65     case ui::ET_MOUSE_PRESSED:
66     case ui::ET_MOUSE_DRAGGED:
67     case ui::ET_MOUSE_RELEASED:
68     case ui::ET_MOUSE_MOVED:
69     case ui::ET_MOUSE_ENTERED:
70     case ui::ET_MOUSE_EXITED:
71     case ui::ET_KEY_PRESSED:
72     case ui::ET_KEY_RELEASED:
73     case ui::ET_MOUSEWHEEL:
74     case ui::ET_MOUSE_CAPTURE_CHANGED:
75     case ui::ET_TOUCH_RELEASED:
76       watcher_->OnMouseUp();
77       break;
78     case ui::ET_TOUCH_PRESSED:
79       watcher_->OnMouseDown(position.x(), position.y());
80       break;
81     case ui::ET_TOUCH_MOVED:
82       watcher_->OnMouseMove(position.x(), position.y());
83       break;
84     case ui::ET_TOUCH_STATIONARY:
85     case ui::ET_TOUCH_CANCELLED:
86     case ui::ET_DROP_TARGET_EVENT:
87     case ui::ET_TRANSLATED_KEY_PRESS:
88     case ui::ET_TRANSLATED_KEY_RELEASE:
89     case ui::ET_GESTURE_SCROLL_BEGIN:
90     case ui::ET_GESTURE_SCROLL_END:
91     case ui::ET_GESTURE_SCROLL_UPDATE:
92     case ui::ET_GESTURE_TAP:
93     case ui::ET_GESTURE_TAP_DOWN:
94     case ui::ET_GESTURE_TAP_CANCEL:
95     case ui::ET_GESTURE_BEGIN:
96     case ui::ET_GESTURE_END:
97     case ui::ET_GESTURE_TWO_FINGER_TAP:
98     case ui::ET_GESTURE_PINCH_BEGIN:
99     case ui::ET_GESTURE_PINCH_END:
100     case ui::ET_GESTURE_PINCH_UPDATE:
101     case ui::ET_GESTURE_LONG_PRESS:
102     case ui::ET_GESTURE_LONG_TAP:
103     case ui::ET_GESTURE_MULTIFINGER_SWIPE:
104     case ui::ET_GESTURE_SHOW_PRESS:
105     case ui::ET_SCROLL:
106     case ui::ET_SCROLL_FLING_START:
107     case ui::ET_SCROLL_FLING_CANCEL:
108     case ui::ET_CANCEL_MODE:
109     case ui::ET_UMA_DATA:
110     case ui::ET_LAST:
111       break;
112   }
113   event->SetHandled();
114 }
115
116 void TizenSystemIndicator::OnMouseMoved(const ui::MouseEvent& event) {
117   if (!IsConnected())
118     return;
119   const gfx::Point position = event.location();
120   watcher_->OnMouseMove(position.x(), position.y());
121 }
122
123 }  // namespace xwalk