views_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/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
21namespace content {
22class WebContents;
23class BrowserContext;
24class SiteInstance;
25}
26
27namespace gfx {
28class Rect;
29}
30
31namespace views {
32
33class NativeWidget;
34class NonClientFrameView;
35class View;
36class Widget;
37namespace internal {
38class NativeWidgetDelegate;
39}
40
41// ViewsDelegate is an interface implemented by an object using the views
42// framework. It is used to obtain various high level application utilities
43// and perform some actions such as window placement saving.
44//
45// The embedding app must set views_delegate to assign its ViewsDelegate
46// implementation.
47class VIEWS_EXPORT ViewsDelegate {
48 public:
49  // The active ViewsDelegate used by the views system.
50  static ViewsDelegate* views_delegate;
51
52  virtual ~ViewsDelegate() {}
53
54  // Saves the position, size and "show" state for the window with the
55  // specified name.
56  virtual void SaveWindowPlacement(const Widget* widget,
57                                   const std::string& window_name,
58                                   const gfx::Rect& bounds,
59                                   ui::WindowShowState show_state) = 0;
60
61  // Retrieves the saved position and size and "show" state for the window with
62  // the specified name.
63  virtual bool GetSavedWindowPlacement(
64      const std::string& window_name,
65      gfx::Rect* bounds,
66      ui::WindowShowState* show_state) const = 0;
67
68  virtual void NotifyAccessibilityEvent(
69      View* view,
70      ui::AccessibilityTypes::Event event_type) = 0;
71
72  // For accessibility, notify the delegate that a menu item was focused
73  // so that alternate feedback (speech / magnified text) can be provided.
74  virtual void NotifyMenuItemFocused(const string16& menu_name,
75                                     const string16& menu_item_name,
76                                     int item_index,
77                                     int item_count,
78                                     bool has_submenu) = 0;
79
80#if defined(OS_WIN)
81  // Retrieves the default window icon to use for windows if none is specified.
82  virtual HICON GetDefaultWindowIcon() const = 0;
83#endif
84
85  // Creates a default NonClientFrameView to be used for windows that don't
86  // specify their own. If this function returns NULL, the
87  // views::CustomFrameView type will be used.
88  virtual NonClientFrameView* CreateDefaultNonClientFrameView(
89      Widget* widget) = 0;
90
91  // Returns whether the embedding app wants windows to be created with the
92  // views::Widget marked as transparent.  For example, an app may wish to
93  // apply transparent window frames in the NonClientFrameView.
94  virtual bool UseTransparentWindows() const = 0;
95
96  // AddRef/ReleaseRef are invoked while a menu is visible. They are used to
97  // ensure we don't attempt to exit while a menu is showing.
98  virtual void AddRef() = 0;
99  virtual void ReleaseRef() = 0;
100
101  // Converts ui::Event::flags to a WindowOpenDisposition.
102  virtual int GetDispositionForEvent(int event_flags) = 0;
103
104  // Creates a web contents. This will return NULL unless overriden.
105  virtual content::WebContents* CreateWebContents(
106      content::BrowserContext* browser_context,
107      content::SiteInstance* site_instance) = 0;
108
109  // Creates a NativeWidget implementation. Returning NULL means Widget will
110  // create a default implementation for the platform.
111  virtual NativeWidget* CreateNativeWidget(
112      Widget::InitParams::Type type,
113      internal::NativeWidgetDelegate* delegate,
114      gfx::NativeView parent) = 0;
115};
116
117}  // namespace views
118
119#endif  // UI_VIEWS_VIEWS_DELEGATE_H_
120