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