Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / views / views_delegate.h
1 // Copyright (c) 2012 The Chromium Authors. 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 #ifndef UI_VIEWS_VIEWS_DELEGATE_H_
6 #define UI_VIEWS_VIEWS_DELEGATE_H_
7
8 #include <string>
9
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #endif
13
14 #include "base/strings/string16.h"
15 #include "ui/accessibility/ax_enums.h"
16 #include "ui/base/ui_base_types.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/views/views_export.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace base {
22 class TimeDelta;
23 }
24
25 namespace content {
26 class WebContents;
27 class BrowserContext;
28 class SiteInstance;
29 }
30
31 namespace gfx {
32 class ImageSkia;
33 class Rect;
34 }
35
36 namespace views {
37
38 class NativeWidget;
39 class NonClientFrameView;
40 class ViewsTouchSelectionControllerFactory;
41 class View;
42 class Widget;
43 namespace internal {
44 class NativeWidgetDelegate;
45 }
46
47 // ViewsDelegate is an interface implemented by an object using the views
48 // framework. It is used to obtain various high level application utilities
49 // and perform some actions such as window placement saving.
50 //
51 // The embedding app must set views_delegate to assign its ViewsDelegate
52 // implementation.
53 class VIEWS_EXPORT ViewsDelegate {
54  public:
55 #if defined(OS_WIN)
56   enum AppbarAutohideEdge {
57     EDGE_TOP    = 1 << 0,
58     EDGE_LEFT   = 1 << 1,
59     EDGE_BOTTOM = 1 << 2,
60     EDGE_RIGHT  = 1 << 3,
61   };
62 #endif
63
64   ViewsDelegate();
65   virtual ~ViewsDelegate();
66
67   // Saves the position, size and "show" state for the window with the
68   // specified name.
69   virtual void SaveWindowPlacement(const Widget* widget,
70                                    const std::string& window_name,
71                                    const gfx::Rect& bounds,
72                                    ui::WindowShowState show_state);
73
74   // Retrieves the saved position and size and "show" state for the window with
75   // the specified name.
76   virtual bool GetSavedWindowPlacement(const Widget* widget,
77                                        const std::string& window_name,
78                                        gfx::Rect* bounds,
79                                        ui::WindowShowState* show_state) const;
80
81   virtual void NotifyAccessibilityEvent(View* view, ui::AXEvent event_type);
82
83   // For accessibility, notify the delegate that a menu item was focused
84   // so that alternate feedback (speech / magnified text) can be provided.
85   virtual void NotifyMenuItemFocused(const base::string16& menu_name,
86                                      const base::string16& menu_item_name,
87                                      int item_index,
88                                      int item_count,
89                                      bool has_submenu);
90
91 #if defined(OS_WIN)
92   // Retrieves the default window icon to use for windows if none is specified.
93   virtual HICON GetDefaultWindowIcon() const;
94   // Returns true if the window passed in is in the Windows 8 metro
95   // environment.
96   virtual bool IsWindowInMetro(gfx::NativeWindow window) const;
97 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
98   virtual gfx::ImageSkia* GetDefaultWindowIcon() const;
99 #endif
100
101   // Creates a default NonClientFrameView to be used for windows that don't
102   // specify their own. If this function returns NULL, the
103   // views::CustomFrameView type will be used.
104   virtual NonClientFrameView* CreateDefaultNonClientFrameView(Widget* widget);
105
106   // AddRef/ReleaseRef are invoked while a menu is visible. They are used to
107   // ensure we don't attempt to exit while a menu is showing.
108   virtual void AddRef();
109   virtual void ReleaseRef();
110
111   // Creates a web contents. This will return NULL unless overriden.
112   virtual content::WebContents* CreateWebContents(
113       content::BrowserContext* browser_context,
114       content::SiteInstance* site_instance);
115
116   // Gives the platform a chance to modify the properties of a Widget.
117   virtual void OnBeforeWidgetInit(Widget::InitParams* params,
118                                   internal::NativeWidgetDelegate* delegate) = 0;
119
120   // Returns the default obscured text reveal duration.
121   virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration();
122
123   // Returns true if the operating system's window manager will always provide a
124   // title bar with caption buttons (ignoring the setting to
125   // |remove_standard_frame| in InitParams). If |maximized|, this applies to
126   // maximized windows; otherwise to restored windows.
127   virtual bool WindowManagerProvidesTitleBar(bool maximized);
128
129 #if defined(OS_WIN)
130   // Starts a query for the appbar autohide edges of the specified monitor and
131   // returns the current value.  If the query finds the edges have changed from
132   // the current value, |callback| is subsequently invoked.  If the edges have
133   // not changed, |callback| is never run.
134   //
135   // The return value is a bitmask of AppbarAutohideEdge.
136   virtual int GetAppbarAutohideEdges(HMONITOR monitor,
137                                      const base::Closure& callback);
138 #endif
139
140   // The active ViewsDelegate used by the views system.
141   static ViewsDelegate* views_delegate;
142
143   virtual void SetShouldShowTitleBar(bool show_title_bar) {
144     should_show_titlebar_ = show_title_bar;
145   }
146   virtual bool ShouldShowTitleBar() const { return  should_show_titlebar_; }
147
148  private:
149   scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
150   // Set to ture if the window should have the title bar.
151   bool should_show_titlebar_;
152
153   DISALLOW_COPY_AND_ASSIGN(ViewsDelegate);
154 };
155
156 }  // namespace views
157
158 #endif  // UI_VIEWS_VIEWS_DELEGATE_H_