e18aff35123237b2e65dc4388738c986de85dcbe
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / views / SkWindow.h
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #ifndef SkWindow_DEFINED
9 #define SkWindow_DEFINED
10
11 #include "SkView.h"
12 #include "SkBitmap.h"
13 #include "SkMatrix.h"
14 #include "SkRegion.h"
15 #include "SkEvent.h"
16 #include "SkKey.h"
17 #include "SkSurfaceProps.h"
18 #include "SkTDArray.h"
19
20 #ifdef SK_BUILD_FOR_WINCEx
21     #define SHOW_FPS
22 #endif
23 //#define USE_GX_SCREEN
24
25 class SkSurface;
26 class SkOSMenu;
27
28 class SkWindow : public SkView {
29 public:
30             SkWindow();
31     virtual ~SkWindow();
32
33     SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
34     void setSurfaceProps(const SkSurfaceProps& props) {
35         fSurfaceProps = props;
36     }
37
38     const SkBitmap& getBitmap() const { return fBitmap; }
39
40     void    setColorType(SkColorType);
41     void    resize(int width, int height, SkColorType = kUnknown_SkColorType);
42
43     bool    isDirty() const { return !fDirtyRgn.isEmpty(); }
44     bool    update(SkIRect* updateArea);
45     // does not call through to onHandleInval(), but does force the fDirtyRgn
46     // to be wide open. Call before update() to ensure we redraw everything.
47     void    forceInvalAll();
48     // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
49     const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
50
51     bool    handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0);
52     bool    handleChar(SkUnichar);
53     bool    handleKey(SkKey);
54     bool    handleKeyUp(SkKey);
55
56     void    addMenu(SkOSMenu*);
57     const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
58
59     const char* getTitle() const { return fTitle.c_str(); }
60     void    setTitle(const char title[]);
61
62     const SkMatrix& getMatrix() const { return fMatrix; }
63     void    setMatrix(const SkMatrix&);
64     void    preConcat(const SkMatrix&);
65     void    postConcat(const SkMatrix&);
66
67     virtual SkSurface* createSurface();
68
69     virtual void onPDFSaved(const char title[], const char desc[],
70         const char path[]) {}
71 protected:
72     virtual bool onEvent(const SkEvent&);
73     virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi);
74     // called if part of our bitmap is invalidated
75     virtual void onHandleInval(const SkIRect&);
76     virtual bool onHandleChar(SkUnichar);
77     virtual bool onHandleKey(SkKey);
78     virtual bool onHandleKeyUp(SkKey);
79     virtual void onAddMenu(const SkOSMenu*) {};
80     virtual void onUpdateMenu(const SkOSMenu*) {};
81     virtual void onSetTitle(const char title[]) {}
82
83     // overrides from SkView
84     virtual bool handleInval(const SkRect*);
85     virtual bool onGetFocusView(SkView** focus) const;
86     virtual bool onSetFocusView(SkView* focus);
87
88 private:
89     SkSurfaceProps  fSurfaceProps;
90     SkColorType fColorType;
91     SkBitmap    fBitmap;
92     SkRegion    fDirtyRgn;
93
94     SkTDArray<Click*>       fClicks; // to track clicks
95
96     SkTDArray<SkOSMenu*>    fMenus;
97
98     SkView* fFocusView;
99     bool    fWaitingOnInval;
100
101     SkString    fTitle;
102     SkMatrix    fMatrix;
103
104     typedef SkView INHERITED;
105 };
106
107 ////////////////////////////////////////////////////////////////////////////////
108
109 #if defined(SK_BUILD_FOR_NACL)
110     #include "SkOSWindow_NaCl.h"
111 #elif defined(SK_BUILD_FOR_MAC)
112     #include "SkOSWindow_Mac.h"
113 #elif defined(SK_BUILD_FOR_WIN)
114     #include "SkOSWindow_Win.h"
115 #elif defined(SK_BUILD_FOR_ANDROID)
116     #include "SkOSWindow_Android.h"
117 #elif defined(SK_BUILD_FOR_UNIX)
118   #include "SkOSWindow_Unix.h"
119 #elif defined(SK_BUILD_FOR_SDL)
120     #include "SkOSWindow_SDL.h"
121 #elif defined(SK_BUILD_FOR_IOS)
122     #include "SkOSWindow_iOS.h"
123 #endif
124
125 #endif