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 #include "ui/views/widget/widget_delegate.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/gfx/image/image_skia.h"
9 #include "ui/views/bubble/bubble_delegate.h"
10 #include "ui/views/view.h"
11 #include "ui/views/views_delegate.h"
12 #include "ui/views/widget/widget.h"
13 #include "ui/views/window/client_view.h"
17 ////////////////////////////////////////////////////////////////////////////////
20 WidgetDelegate::WidgetDelegate()
21 : default_contents_view_(NULL
),
25 void WidgetDelegate::OnWidgetMove() {
28 void WidgetDelegate::OnDisplayChanged() {
31 void WidgetDelegate::OnWorkAreaChanged() {
34 View
* WidgetDelegate::GetInitiallyFocusedView() {
38 BubbleDelegateView
* WidgetDelegate::AsBubbleDelegate() {
42 DialogDelegate
* WidgetDelegate::AsDialogDelegate() {
46 bool WidgetDelegate::CanResize() const {
50 bool WidgetDelegate::CanMaximize() const {
54 bool WidgetDelegate::CanMinimize() const {
58 bool WidgetDelegate::CanActivate() const {
62 ui::ModalType
WidgetDelegate::GetModalType() const {
63 return ui::MODAL_TYPE_NONE
;
66 ui::AXRole
WidgetDelegate::GetAccessibleWindowRole() const {
67 return ui::AX_ROLE_WINDOW
;
70 base::string16
WidgetDelegate::GetAccessibleWindowTitle() const {
71 return GetWindowTitle();
74 base::string16
WidgetDelegate::GetWindowTitle() const {
75 return base::string16();
78 bool WidgetDelegate::ShouldShowWindowTitle() const {
82 bool WidgetDelegate::ShouldShowCloseButton() const {
86 bool WidgetDelegate::ShouldHandleSystemCommands() const {
87 const Widget
* widget
= GetWidget();
91 return widget
->non_client_view() != NULL
;
94 gfx::ImageSkia
WidgetDelegate::GetWindowAppIcon() {
95 // Use the window icon as app icon by default.
96 return GetWindowIcon();
99 // Returns the icon to be displayed in the window.
100 gfx::ImageSkia
WidgetDelegate::GetWindowIcon() {
101 return gfx::ImageSkia();
104 bool WidgetDelegate::ShouldShowWindowIcon() const {
108 bool WidgetDelegate::ExecuteWindowsCommand(int command_id
) {
112 std::string
WidgetDelegate::GetWindowName() const {
113 return std::string();
116 void WidgetDelegate::SaveWindowPlacement(const gfx::Rect
& bounds
,
117 ui::WindowShowState show_state
) {
118 std::string window_name
= GetWindowName();
119 if (!ViewsDelegate::GetInstance() || window_name
.empty())
122 ViewsDelegate::GetInstance()->SaveWindowPlacement(GetWidget(), window_name
,
126 bool WidgetDelegate::GetSavedWindowPlacement(
127 const Widget
* widget
,
129 ui::WindowShowState
* show_state
) const {
130 std::string window_name
= GetWindowName();
131 if (!ViewsDelegate::GetInstance() || window_name
.empty())
134 return ViewsDelegate::GetInstance()->GetSavedWindowPlacement(
135 widget
, window_name
, bounds
, show_state
);
138 bool WidgetDelegate::ShouldRestoreWindowSize() const {
142 View
* WidgetDelegate::GetContentsView() {
143 if (!default_contents_view_
)
144 default_contents_view_
= new View
;
145 return default_contents_view_
;
148 ClientView
* WidgetDelegate::CreateClientView(Widget
* widget
) {
149 return new ClientView(widget
, GetContentsView());
152 NonClientFrameView
* WidgetDelegate::CreateNonClientFrameView(Widget
* widget
) {
156 View
* WidgetDelegate::CreateOverlayView() {
160 bool WidgetDelegate::WillProcessWorkAreaChange() const {
164 bool WidgetDelegate::WidgetHasHitTestMask() const {
168 void WidgetDelegate::GetWidgetHitTestMask(gfx::Path
* mask
) const {
172 bool WidgetDelegate::ShouldAdvanceFocusToTopLevelWidget() const {
176 bool WidgetDelegate::ShouldDescendIntoChildForEventHandling(
177 gfx::NativeView child
,
178 const gfx::Point
& location
) {
182 ////////////////////////////////////////////////////////////////////////////////
183 // WidgetDelegateView:
186 const char WidgetDelegateView::kViewClassName
[] = "WidgetDelegateView";
188 WidgetDelegateView::WidgetDelegateView() {
189 // A WidgetDelegate should be deleted on DeleteDelegate.
190 set_owned_by_client();
193 WidgetDelegateView::~WidgetDelegateView() {
196 void WidgetDelegateView::DeleteDelegate() {
200 Widget
* WidgetDelegateView::GetWidget() {
201 return View::GetWidget();
204 const Widget
* WidgetDelegateView::GetWidget() const {
205 return View::GetWidget();
208 const char* WidgetDelegateView::GetClassName() const {
209 return kViewClassName
;