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