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/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"
39 class NonClientFrameView;
40 class ViewsTouchSelectionControllerFactory;
44 class NativeWidgetDelegate;
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.
51 // The embedding app must set views_delegate to assign its ViewsDelegate
53 class VIEWS_EXPORT ViewsDelegate {
56 enum AppbarAutohideEdge {
65 virtual ~ViewsDelegate();
67 // Saves the position, size and "show" state for the window with the
69 virtual void SaveWindowPlacement(const Widget* widget,
70 const std::string& window_name,
71 const gfx::Rect& bounds,
72 ui::WindowShowState show_state);
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,
79 ui::WindowShowState* show_state) const;
81 virtual void NotifyAccessibilityEvent(View* view, ui::AXEvent event_type);
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,
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
96 virtual bool IsWindowInMetro(gfx::NativeWindow window) const;
97 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
98 virtual gfx::ImageSkia* GetDefaultWindowIcon() const;
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);
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();
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);
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;
120 // Returns the default obscured text reveal duration.
121 virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration();
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);
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.
135 // The return value is a bitmask of AppbarAutohideEdge.
136 virtual int GetAppbarAutohideEdges(HMONITOR monitor,
137 const base::Closure& callback);
140 // The active ViewsDelegate used by the views system.
141 static ViewsDelegate* views_delegate;
143 virtual void SetShouldShowTitleBar(bool show_title_bar) {
144 should_show_titlebar_ = show_title_bar;
146 virtual bool ShouldShowTitleBar() const { return should_show_titlebar_; }
149 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
150 // Set to ture if the window should have the title bar.
151 bool should_show_titlebar_;
153 DISALLOW_COPY_AND_ASSIGN(ViewsDelegate);
158 #endif // UI_VIEWS_VIEWS_DELEGATE_H_