Update V8 to version 4.7.57.
[chromium-blink-merge.git] / ui / views / views_delegate.h
blobc881daab09f34eae37173da7ee7d292af26f5fe4
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.
5 #ifndef UI_VIEWS_VIEWS_DELEGATE_H_
6 #define UI_VIEWS_VIEWS_DELEGATE_H_
8 #include <string>
10 #if defined(OS_WIN)
11 #include <windows.h>
12 #endif
14 #include "base/callback.h"
15 #include "base/location.h"
16 #include "base/strings/string16.h"
17 #include "ui/accessibility/ax_enums.h"
18 #include "ui/base/ui_base_types.h"
19 #include "ui/gfx/native_widget_types.h"
20 #include "ui/views/views_export.h"
21 #include "ui/views/widget/widget.h"
23 namespace base {
24 class TaskRunner;
25 class TimeDelta;
28 namespace content {
29 class WebContents;
30 class BrowserContext;
31 class SiteInstance;
34 namespace gfx {
35 class ImageSkia;
36 class Rect;
39 namespace ui {
40 class ContextFactory;
43 namespace views {
45 class NativeWidget;
46 class NonClientFrameView;
47 class ViewsTouchEditingControllerFactory;
48 class View;
49 class Widget;
51 #if defined(USE_AURA)
52 class TouchSelectionMenuRunnerViews;
53 #endif
55 namespace internal {
56 class NativeWidgetDelegate;
59 // ViewsDelegate is an interface implemented by an object using the views
60 // framework. It is used to obtain various high level application utilities
61 // and perform some actions such as window placement saving.
63 // The embedding app must set the ViewsDelegate instance by instantiating an
64 // implementation of ViewsDelegate (the constructor will set the instance).
65 class VIEWS_EXPORT ViewsDelegate {
66 public:
67 #if defined(OS_WIN)
68 enum AppbarAutohideEdge {
69 EDGE_TOP = 1 << 0,
70 EDGE_LEFT = 1 << 1,
71 EDGE_BOTTOM = 1 << 2,
72 EDGE_RIGHT = 1 << 3,
74 #endif
76 enum class ProcessMenuAcceleratorResult {
77 // The accelerator was handled while the menu was showing. No further action
78 // is needed and the menu should be kept open.
79 LEAVE_MENU_OPEN,
81 // The accelerator was not handled. Menu should be closed and the
82 // accelerator will be reposted to be handled after the menu closes.
83 CLOSE_MENU
86 virtual ~ViewsDelegate();
88 // Returns the ViewsDelegate instance if there is one, or nullptr otherwise.
89 static ViewsDelegate* GetInstance();
91 // Saves the position, size and "show" state for the window with the
92 // specified name.
93 virtual void SaveWindowPlacement(const Widget* widget,
94 const std::string& window_name,
95 const gfx::Rect& bounds,
96 ui::WindowShowState show_state);
98 // Retrieves the saved position and size and "show" state for the window with
99 // the specified name.
100 virtual bool GetSavedWindowPlacement(const Widget* widget,
101 const std::string& window_name,
102 gfx::Rect* bounds,
103 ui::WindowShowState* show_state) const;
105 virtual void NotifyAccessibilityEvent(View* view, ui::AXEvent event_type);
107 // For accessibility, notify the delegate that a menu item was focused
108 // so that alternate feedback (speech / magnified text) can be provided.
109 virtual void NotifyMenuItemFocused(const base::string16& menu_name,
110 const base::string16& menu_item_name,
111 int item_index,
112 int item_count,
113 bool has_submenu);
115 // If |accelerator| can be processed while a menu is showing, it will be
116 // processed now and LEAVE_MENU_OPEN is returned. Otherwise, |accelerator|
117 // will be reposted for processing later after the menu closes and CLOSE_MENU
118 // will be returned.
119 virtual ProcessMenuAcceleratorResult ProcessAcceleratorWhileMenuShowing(
120 const ui::Accelerator& accelerator);
122 #if defined(OS_WIN)
123 // Retrieves the default window icon to use for windows if none is specified.
124 virtual HICON GetDefaultWindowIcon() const;
125 // Retrieves the small window icon to use for windows if none is specified.
126 virtual HICON GetSmallWindowIcon() const = 0;
127 // Returns true if the window passed in is in the Windows 8 metro
128 // environment.
129 virtual bool IsWindowInMetro(gfx::NativeWindow window) const;
130 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
131 virtual gfx::ImageSkia* GetDefaultWindowIcon() const;
132 #endif
134 // Creates a default NonClientFrameView to be used for windows that don't
135 // specify their own. If this function returns NULL, the
136 // views::CustomFrameView type will be used.
137 virtual NonClientFrameView* CreateDefaultNonClientFrameView(Widget* widget);
139 // AddRef/ReleaseRef are invoked while a menu is visible. They are used to
140 // ensure we don't attempt to exit while a menu is showing.
141 virtual void AddRef();
142 virtual void ReleaseRef();
144 // Creates a web contents. This will return NULL unless overriden.
145 virtual content::WebContents* CreateWebContents(
146 content::BrowserContext* browser_context,
147 content::SiteInstance* site_instance);
149 // Gives the platform a chance to modify the properties of a Widget.
150 virtual void OnBeforeWidgetInit(Widget::InitParams* params,
151 internal::NativeWidgetDelegate* delegate) = 0;
153 // Returns the default obscured text reveal duration.
154 virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration();
156 // Returns true if the operating system's window manager will always provide a
157 // title bar with caption buttons (ignoring the setting to
158 // |remove_standard_frame| in InitParams). If |maximized|, this applies to
159 // maximized windows; otherwise to restored windows.
160 virtual bool WindowManagerProvidesTitleBar(bool maximized);
162 // Returns the context factory for new windows.
163 virtual ui::ContextFactory* GetContextFactory();
165 // Returns the user-visible name of the application.
166 virtual std::string GetApplicationName();
168 #if defined(OS_WIN)
169 // Starts a query for the appbar autohide edges of the specified monitor and
170 // returns the current value. If the query finds the edges have changed from
171 // the current value, |callback| is subsequently invoked. If the edges have
172 // not changed, |callback| is never run.
174 // The return value is a bitmask of AppbarAutohideEdge.
175 virtual int GetAppbarAutohideEdges(HMONITOR monitor,
176 const base::Closure& callback);
177 #endif
179 // Returns a blocking pool task runner given a TaskRunnerType.
180 virtual scoped_refptr<base::TaskRunner> GetBlockingPoolTaskRunner();
182 protected:
183 ViewsDelegate();
185 private:
186 scoped_ptr<ViewsTouchEditingControllerFactory> views_tsc_factory_;
188 #if defined(USE_AURA)
189 scoped_ptr<TouchSelectionMenuRunnerViews> touch_selection_menu_runner_;
190 #endif
192 DISALLOW_COPY_AND_ASSIGN(ViewsDelegate);
195 } // namespace views
197 #endif // UI_VIEWS_VIEWS_DELEGATE_H_