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::CanActivate() const {
58 ui::ModalType
WidgetDelegate::GetModalType() const {
59 return ui::MODAL_TYPE_NONE
;
62 ui::AXRole
WidgetDelegate::GetAccessibleWindowRole() const {
63 return ui::AX_ROLE_WINDOW
;
66 base::string16
WidgetDelegate::GetAccessibleWindowTitle() const {
67 return GetWindowTitle();
70 base::string16
WidgetDelegate::GetWindowTitle() const {
71 return base::string16();
74 bool WidgetDelegate::ShouldShowWindowTitle() const {
78 bool WidgetDelegate::ShouldShowCloseButton() const {
82 bool WidgetDelegate::ShouldHandleSystemCommands() const {
83 const Widget
* widget
= GetWidget();
87 return widget
->non_client_view() != NULL
;
90 gfx::ImageSkia
WidgetDelegate::GetWindowAppIcon() {
91 // Use the window icon as app icon by default.
92 return GetWindowIcon();
95 // Returns the icon to be displayed in the window.
96 gfx::ImageSkia
WidgetDelegate::GetWindowIcon() {
97 return gfx::ImageSkia();
100 bool WidgetDelegate::ShouldShowWindowIcon() const {
104 bool WidgetDelegate::ExecuteWindowsCommand(int command_id
) {
108 std::string
WidgetDelegate::GetWindowName() const {
109 return std::string();
112 void WidgetDelegate::SaveWindowPlacement(const gfx::Rect
& bounds
,
113 ui::WindowShowState show_state
) {
114 std::string window_name
= GetWindowName();
115 if (!ViewsDelegate::views_delegate
|| window_name
.empty())
118 ViewsDelegate::views_delegate
->SaveWindowPlacement(
119 GetWidget(), window_name
, bounds
, show_state
);
122 bool WidgetDelegate::GetSavedWindowPlacement(
123 const Widget
* widget
,
125 ui::WindowShowState
* show_state
) const {
126 std::string window_name
= GetWindowName();
127 if (!ViewsDelegate::views_delegate
|| window_name
.empty())
130 return ViewsDelegate::views_delegate
->GetSavedWindowPlacement(
131 widget
, window_name
, bounds
, show_state
);
134 bool WidgetDelegate::ShouldRestoreWindowSize() const {
138 View
* WidgetDelegate::GetContentsView() {
139 if (!default_contents_view_
)
140 default_contents_view_
= new View
;
141 return default_contents_view_
;
144 ClientView
* WidgetDelegate::CreateClientView(Widget
* widget
) {
145 return new ClientView(widget
, GetContentsView());
148 NonClientFrameView
* WidgetDelegate::CreateNonClientFrameView(Widget
* widget
) {
152 View
* WidgetDelegate::CreateOverlayView() {
156 bool WidgetDelegate::WillProcessWorkAreaChange() const {
160 bool WidgetDelegate::WidgetHasHitTestMask() const {
164 void WidgetDelegate::GetWidgetHitTestMask(gfx::Path
* mask
) const {
168 bool WidgetDelegate::ShouldAdvanceFocusToTopLevelWidget() const {
172 bool WidgetDelegate::ShouldDescendIntoChildForEventHandling(
173 gfx::NativeView child
,
174 const gfx::Point
& location
) {
178 ////////////////////////////////////////////////////////////////////////////////
179 // WidgetDelegateView:
181 WidgetDelegateView::WidgetDelegateView() {
182 // A WidgetDelegate should be deleted on DeleteDelegate.
183 set_owned_by_client();
186 WidgetDelegateView::~WidgetDelegateView() {
189 void WidgetDelegateView::DeleteDelegate() {
193 Widget
* WidgetDelegateView::GetWidget() {
194 return View::GetWidget();
197 const Widget
* WidgetDelegateView::GetWidget() const {
198 return View::GetWidget();