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