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_
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"
46 class NonClientFrameView
;
47 class ViewsTouchEditingControllerFactory
;
52 class TouchSelectionMenuRunnerViews
;
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
{
68 enum AppbarAutohideEdge
{
76 virtual ~ViewsDelegate();
78 // Returns the ViewsDelegate instance if there is one, or nullptr otherwise.
79 static ViewsDelegate
* GetInstance();
81 // Saves the position, size and "show" state for the window with the
83 virtual void SaveWindowPlacement(const Widget
* widget
,
84 const std::string
& window_name
,
85 const gfx::Rect
& bounds
,
86 ui::WindowShowState show_state
);
88 // Retrieves the saved position and size and "show" state for the window with
89 // the specified name.
90 virtual bool GetSavedWindowPlacement(const Widget
* widget
,
91 const std::string
& window_name
,
93 ui::WindowShowState
* show_state
) const;
95 virtual void NotifyAccessibilityEvent(View
* view
, ui::AXEvent event_type
);
97 // For accessibility, notify the delegate that a menu item was focused
98 // so that alternate feedback (speech / magnified text) can be provided.
99 virtual void NotifyMenuItemFocused(const base::string16
& menu_name
,
100 const base::string16
& menu_item_name
,
106 // Retrieves the default window icon to use for windows if none is specified.
107 virtual HICON
GetDefaultWindowIcon() const;
108 // Retrieves the small window icon to use for windows if none is specified.
109 virtual HICON
GetSmallWindowIcon() const = 0;
110 // Returns true if the window passed in is in the Windows 8 metro
112 virtual bool IsWindowInMetro(gfx::NativeWindow window
) const;
113 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
114 virtual gfx::ImageSkia
* GetDefaultWindowIcon() const;
117 // Creates a default NonClientFrameView to be used for windows that don't
118 // specify their own. If this function returns NULL, the
119 // views::CustomFrameView type will be used.
120 virtual NonClientFrameView
* CreateDefaultNonClientFrameView(Widget
* widget
);
122 // AddRef/ReleaseRef are invoked while a menu is visible. They are used to
123 // ensure we don't attempt to exit while a menu is showing.
124 virtual void AddRef();
125 virtual void ReleaseRef();
127 // Creates a web contents. This will return NULL unless overriden.
128 virtual content::WebContents
* CreateWebContents(
129 content::BrowserContext
* browser_context
,
130 content::SiteInstance
* site_instance
);
132 // Gives the platform a chance to modify the properties of a Widget.
133 virtual void OnBeforeWidgetInit(Widget::InitParams
* params
,
134 internal::NativeWidgetDelegate
* delegate
) = 0;
136 // Returns the default obscured text reveal duration.
137 virtual base::TimeDelta
GetDefaultTextfieldObscuredRevealDuration();
139 // Returns true if the operating system's window manager will always provide a
140 // title bar with caption buttons (ignoring the setting to
141 // |remove_standard_frame| in InitParams). If |maximized|, this applies to
142 // maximized windows; otherwise to restored windows.
143 virtual bool WindowManagerProvidesTitleBar(bool maximized
);
145 // Returns the context factory for new windows.
146 virtual ui::ContextFactory
* GetContextFactory();
148 // Returns the user-visible name of the application.
149 virtual std::string
GetApplicationName();
152 // Starts a query for the appbar autohide edges of the specified monitor and
153 // returns the current value. If the query finds the edges have changed from
154 // the current value, |callback| is subsequently invoked. If the edges have
155 // not changed, |callback| is never run.
157 // The return value is a bitmask of AppbarAutohideEdge.
158 virtual int GetAppbarAutohideEdges(HMONITOR monitor
,
159 const base::Closure
& callback
);
162 // Returns a blocking pool task runner given a TaskRunnerType.
163 virtual scoped_refptr
<base::TaskRunner
> GetBlockingPoolTaskRunner();
169 scoped_ptr
<ViewsTouchEditingControllerFactory
> views_tsc_factory_
;
171 #if defined(USE_AURA)
172 scoped_ptr
<TouchSelectionMenuRunnerViews
> touch_selection_menu_runner_
;
175 DISALLOW_COPY_AND_ASSIGN(ViewsDelegate
);
180 #endif // UI_VIEWS_VIEWS_DELEGATE_H_