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/base/accessibility/accessibility_types.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 // The active ViewsDelegate used by the views system. 56 static ViewsDelegate* views_delegate; 57 58 ViewsDelegate(); 59 60 virtual ~ViewsDelegate(); 61 62 // Saves the position, size and "show" state for the window with the 63 // specified name. 64 virtual void SaveWindowPlacement(const Widget* widget, 65 const std::string& window_name, 66 const gfx::Rect& bounds, 67 ui::WindowShowState show_state) = 0; 68 69 // Retrieves the saved position and size and "show" state for the window with 70 // the specified name. 71 virtual bool GetSavedWindowPlacement( 72 const Widget* widget, 73 const std::string& window_name, 74 gfx::Rect* bounds, 75 ui::WindowShowState* show_state) const = 0; 76 77 virtual void NotifyAccessibilityEvent( 78 View* view, 79 ui::AccessibilityTypes::Event event_type) = 0; 80 81 // For accessibility, notify the delegate that a menu item was focused 82 // so that alternate feedback (speech / magnified text) can be provided. 83 virtual void NotifyMenuItemFocused(const string16& menu_name, 84 const string16& menu_item_name, 85 int item_index, 86 int item_count, 87 bool has_submenu) = 0; 88 89 #if defined(OS_WIN) 90 // Retrieves the default window icon to use for windows if none is specified. 91 virtual HICON GetDefaultWindowIcon() const = 0; 92 // Returns true if the window passed in is in the Windows 8 metro 93 // environment. 94 virtual bool IsWindowInMetro(gfx::NativeWindow window) const = 0; 95 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) 96 virtual gfx::ImageSkia* GetDefaultWindowIcon() const = 0; 97 #endif 98 99 // Creates a default NonClientFrameView to be used for windows that don't 100 // specify their own. If this function returns NULL, the 101 // views::CustomFrameView type will be used. 102 virtual NonClientFrameView* CreateDefaultNonClientFrameView( 103 Widget* widget) = 0; 104 105 // Returns whether the embedding app wants windows to be created with the 106 // views::Widget marked as transparent. For example, an app may wish to 107 // apply transparent window frames in the NonClientFrameView. 108 virtual bool UseTransparentWindows() const = 0; 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() = 0; 113 virtual void ReleaseRef() = 0; 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) = 0; 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() = 0; 126 127 private: 128 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; 129 }; 130 131 } // namespace views 132 133 #endif // UI_VIEWS_VIEWS_DELEGATE_H_ 134