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 #include "ui/views/widget/widget_delegate.h" 6 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" 14 15 namespace views { 16 17 //////////////////////////////////////////////////////////////////////////////// 18 // WidgetDelegate: 19 20 WidgetDelegate::WidgetDelegate() 21 : default_contents_view_(NULL), 22 can_activate_(true) { 23 } 24 25 void WidgetDelegate::OnWidgetMove() { 26 } 27 28 void WidgetDelegate::OnDisplayChanged() { 29 } 30 31 void WidgetDelegate::OnWorkAreaChanged() { 32 } 33 34 View* WidgetDelegate::GetInitiallyFocusedView() { 35 return NULL; 36 } 37 38 BubbleDelegateView* WidgetDelegate::AsBubbleDelegate() { 39 return NULL; 40 } 41 42 DialogDelegate* WidgetDelegate::AsDialogDelegate() { 43 return NULL; 44 } 45 46 bool WidgetDelegate::CanResize() const { 47 return false; 48 } 49 50 bool WidgetDelegate::CanMaximize() const { 51 return false; 52 } 53 54 bool WidgetDelegate::CanMinimize() const { 55 return false; 56 } 57 58 bool WidgetDelegate::CanActivate() const { 59 return can_activate_; 60 } 61 62 ui::ModalType WidgetDelegate::GetModalType() const { 63 return ui::MODAL_TYPE_NONE; 64 } 65 66 ui::AXRole WidgetDelegate::GetAccessibleWindowRole() const { 67 return ui::AX_ROLE_WINDOW; 68 } 69 70 base::string16 WidgetDelegate::GetAccessibleWindowTitle() const { 71 return GetWindowTitle(); 72 } 73 74 base::string16 WidgetDelegate::GetWindowTitle() const { 75 return base::string16(); 76 } 77 78 bool WidgetDelegate::ShouldShowWindowTitle() const { 79 return true; 80 } 81 82 bool WidgetDelegate::ShouldShowCloseButton() const { 83 return true; 84 } 85 86 bool WidgetDelegate::ShouldHandleSystemCommands() const { 87 const Widget* widget = GetWidget(); 88 if (!widget) 89 return false; 90 91 return widget->non_client_view() != NULL; 92 } 93 94 gfx::ImageSkia WidgetDelegate::GetWindowAppIcon() { 95 // Use the window icon as app icon by default. 96 return GetWindowIcon(); 97 } 98 99 // Returns the icon to be displayed in the window. 100 gfx::ImageSkia WidgetDelegate::GetWindowIcon() { 101 return gfx::ImageSkia(); 102 } 103 104 bool WidgetDelegate::ShouldShowWindowIcon() const { 105 return false; 106 } 107 108 bool WidgetDelegate::ExecuteWindowsCommand(int command_id) { 109 return false; 110 } 111 112 std::string WidgetDelegate::GetWindowName() const { 113 return std::string(); 114 } 115 116 void WidgetDelegate::SaveWindowPlacement(const gfx::Rect& bounds, 117 ui::WindowShowState show_state) { 118 std::string window_name = GetWindowName(); 119 if (!ViewsDelegate::views_delegate || window_name.empty()) 120 return; 121 122 ViewsDelegate::views_delegate->SaveWindowPlacement( 123 GetWidget(), window_name, bounds, show_state); 124 } 125 126 bool WidgetDelegate::GetSavedWindowPlacement( 127 const Widget* widget, 128 gfx::Rect* bounds, 129 ui::WindowShowState* show_state) const { 130 std::string window_name = GetWindowName(); 131 if (!ViewsDelegate::views_delegate || window_name.empty()) 132 return false; 133 134 return ViewsDelegate::views_delegate->GetSavedWindowPlacement( 135 widget, window_name, bounds, show_state); 136 } 137 138 bool WidgetDelegate::ShouldRestoreWindowSize() const { 139 return true; 140 } 141 142 View* WidgetDelegate::GetContentsView() { 143 if (!default_contents_view_) 144 default_contents_view_ = new View; 145 return default_contents_view_; 146 } 147 148 ClientView* WidgetDelegate::CreateClientView(Widget* widget) { 149 return new ClientView(widget, GetContentsView()); 150 } 151 152 NonClientFrameView* WidgetDelegate::CreateNonClientFrameView(Widget* widget) { 153 return NULL; 154 } 155 156 View* WidgetDelegate::CreateOverlayView() { 157 return NULL; 158 } 159 160 bool WidgetDelegate::WillProcessWorkAreaChange() const { 161 return false; 162 } 163 164 bool WidgetDelegate::WidgetHasHitTestMask() const { 165 return false; 166 } 167 168 void WidgetDelegate::GetWidgetHitTestMask(gfx::Path* mask) const { 169 DCHECK(mask); 170 } 171 172 bool WidgetDelegate::ShouldAdvanceFocusToTopLevelWidget() const { 173 return false; 174 } 175 176 bool WidgetDelegate::ShouldDescendIntoChildForEventHandling( 177 gfx::NativeView child, 178 const gfx::Point& location) { 179 return true; 180 } 181 182 //////////////////////////////////////////////////////////////////////////////// 183 // WidgetDelegateView: 184 185 WidgetDelegateView::WidgetDelegateView() { 186 // A WidgetDelegate should be deleted on DeleteDelegate. 187 set_owned_by_client(); 188 } 189 190 WidgetDelegateView::~WidgetDelegateView() { 191 } 192 193 void WidgetDelegateView::DeleteDelegate() { 194 delete this; 195 } 196 197 Widget* WidgetDelegateView::GetWidget() { 198 return View::GetWidget(); 199 } 200 201 const Widget* WidgetDelegateView::GetWidget() const { 202 return View::GetWidget(); 203 } 204 205 } // namespace views 206