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