webappmanager
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WindowedWebApp.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef WINDOWEDWEBAPP_H
23 #define WINDOWEDWEBAPP_H
24 
25 #include "Common.h"
26 
27 #include <list>
28 
29 #include "AsyncCaller.h"
30 #include "WebAppBase.h"
31 #include "sptr.h"
32 #include "Event.h"
33 #include "Timer.h"
34 #include "WindowProperties.h"
35 #include "WindowTypes.h"
36 #include <PIpcChannelListener.h>
37 #include <PIpcBuffer.h>
38 #include <QRect>
39 
40 class SysMgrKeyEvent;
41 class QKeyEvent;
42 class SysMgrTouchEvent;
43 class RemoteWindowData;
44 class WindowMetaData;
45 class QTimer;
46 
48 {
49  Q_OBJECT
50 public:
51 
52  WindowedWebApp(int width, int height, WindowType::Type type, PIpcChannel *channel = 0);
53  virtual ~WindowedWebApp();
54 
55  virtual void attach(SysMgrWebBridge* page);
56 
57  virtual void paint();
58 
59  virtual void inputEvent(sptr<Event>);
60  virtual void keyEvent(QKeyEvent* e);
61  virtual void focusedEvent(bool focused);
62  virtual int resizeEvent(int newWidth, int newHeight, bool resizeBuffer);
63  virtual void flipEvent(int newWidth, int newHeight);
64  virtual void asyncFlipEvent(int newWidth, int newHeight, int newScreenWidth, int newScreenHeight);
65 
66  virtual bool isWindowed() const { return true; }
67  virtual bool isCardApp() const { return false; }
68  virtual bool isDashboardApp() const { return false; }
69  virtual bool isLeafApp() const { return true; }
70 
71  virtual WindowType::Type windowType() const { return m_winType; };
72 
73  virtual void setOrientation(Event::Orientation orient) {}
74 
75  virtual void invalidate();
76 
77  virtual bool isFocused() const { return m_focused; }
78 
79  virtual void applyLaunchFeedback(int cx, int cy);
80 
81  int windowWidth() const { return m_windowWidth; }
82  int windowHeight() const { return m_windowHeight; }
83 
84  virtual void onMessageReceived(const PIpcMessage& msg);
85  virtual void onDisconnected();
86  virtual int getKey() const;
87  int routingId() const;
88  int metadataId() const;
89 
90  virtual void onResize(int width, int height, bool resizeBuffer);
91  virtual void onFlip(int newWidth, int newHeight);
92  virtual void onAsyncFlip(int newWidth, int newHeight, int newScreenWidth, int newScreenHeight);
93  virtual void onSyncResize(int width, int height, bool resizeBuffer, int* newKey);
94  virtual void onAdjustForPositiveSpace(int width, int height);
95  virtual void onKeyboardShow(bool val);
96  virtual void onClose(bool disableKeepAlive);
97  virtual void onInputEvent(const SysMgrEventWrapper& wrapper);
98  virtual void onKeyEvent(const SysMgrKeyEvent& keyEvent);
99  virtual void onTouchEvent(const SysMgrTouchEvent& touchEvent);
100  virtual void onDirectRenderingChanged();
101  virtual void onClipboardEvent_Cut();
102  virtual void onClipboardEvent_Copy();
103  virtual void onClipboardEvent_Paste();
104  virtual void onSelectAll();
105 
106  virtual void onSetComposingText(const std::string& text);
107  virtual void onCommitComposingText();
108 
109  virtual void onCommitText(const std::string& text);
110 
111  virtual void onPerformEditorAction(int action);
112 
113  virtual void onRemoveInputFocus();
114 
115  virtual void windowSize(int& width, int& height);
116  virtual void screenSize(int& width, int& height);
117 
118  virtual void setWindowProperties(WindowProperties &winProp);
119 
120  virtual void displayOn() {}
121  virtual void displayOff() {}
122 
123 public Q_SLOTS:
127  void closeWindowRequest();
128 
129 protected:
130 
131  // Call this from subclasses after setting width and height
132  void init();
133 
134  virtual void focus();
135  virtual void unfocus();
136  virtual void invalContents(int x, int y, int width, int height);
137  virtual void scrollContents(int newContentsX, int newContentsY);
138  virtual void loadFinished();
139  virtual void stagePreparing();
140  virtual void stageReady();
141  virtual void editorFocusChanged(bool focused, const PalmIME::EditorState& state);
142  virtual void autoCapEnabled(bool enabled);
143  virtual void needTouchEvents(bool needTouchEvents);
144  virtual void getWindowPropertiesString(WindowProperties &winProp, std::string &propString) const;
145 
146 protected Q_SLOTS:
147  void slotInvalidateRect(const QRect&);
148  void slotResizeContent(const QSize&);
149  void slotGeometryChanged(const QRect&);
150 
151 protected:
152 
153  void startPaintTimer();
154  void stopPaintTimer();
155 
160  };
161 
163  PIpcBuffer* m_metaDataBuffer;
165 
166  WindowType::Type m_winType;
167  int m_width;
168  int m_height;
173 
174  uint32_t m_windowWidth;
175  uint32_t m_windowHeight;
176 
177  QRect m_paintRect;
178 
179  int m_blockCount; //Keeps track on how many PenDown's we blocked.
183  bool m_focused;
185 
186  Timer<WindowedWebApp> m_showWindowTimer;
187 
189 
190  WindowProperties m_winProps;
191 
192 protected Q_SLOTS:
193  void PrvCbPaintTimeout();
194 
195 protected:
196 
197  void renderPageStatistics(int offsetX=0, int offsetY=0);
198  void renderMetaHint(int offsetX=0, int offsetY=0);
199  bool showWindowTimeout();
200  bool appLoaded() const;
201  bool isTransparent() const;
202 
203 private:
204 
205  struct RecordedGestureEntry {
206  RecordedGestureEntry(float s, float r, int cX, int cY)
207  : scale(s)
208  , rotate(r)
209  , centerX(cX)
210  , centerY(cY) {
211  }
212 
213  float scale;
214  float rotate;
215  int centerX;
216  int centerY;
217  };
218 
219  std::list<RecordedGestureEntry> m_recordedGestures;
220 
221  void recordGesture(float s, float r, int cX, int cY);
222  RecordedGestureEntry getAveragedGesture() const;
223 
224  void keyGesture(QKeyEvent* e);
225  QTimer* m_paintTimer;
226 
227 private:
228 
229  WindowedWebApp& operator=(const WindowedWebApp&);
231 
232  friend class WebAppBase;
233  friend class SysMgrWebBridge;
234 };
235 
236 #endif /* WINDOWEDWEBAPP_H */