| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "views/widget/native_widget_aura.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "ui/aura/client/aura_constants.h" | |
| 10 #include "ui/aura/client/drag_drop_client.h" | |
| 11 #include "ui/aura/client/shadow_types.h" | |
| 12 #include "ui/aura/desktop.h" | |
| 13 #include "ui/aura/desktop_observer.h" | |
| 14 #include "ui/aura/event.h" | |
| 15 #include "ui/aura/window.h" | |
| 16 #include "ui/aura/window_types.h" | |
| 17 #include "ui/base/dragdrop/os_exchange_data.h" | |
| 18 #include "ui/base/ui_base_types.h" | |
| 19 #include "ui/gfx/canvas.h" | |
| 20 #include "ui/gfx/compositor/layer.h" | |
| 21 #include "ui/gfx/font.h" | |
| 22 #include "ui/gfx/screen.h" | |
| 23 #include "views/widget/drop_helper.h" | |
| 24 #include "views/widget/native_widget_delegate.h" | |
| 25 #include "views/widget/tooltip_manager_views.h" | |
| 26 | |
| 27 #if defined(OS_WIN) | |
| 28 #include "base/win/scoped_gdi_object.h" | |
| 29 #include "base/win/win_util.h" | |
| 30 #include "ui/base/l10n/l10n_util_win.h" | |
| 31 #endif | |
| 32 | |
| 33 #if defined(HAVE_IBUS) | |
| 34 #include "ui/views/ime/input_method_ibus.h" | |
| 35 #else | |
| 36 #include "ui/views/ime/mock_input_method.h" | |
| 37 #endif | |
| 38 | |
| 39 namespace views { | |
| 40 | |
| 41 namespace { | |
| 42 | |
| 43 aura::WindowType GetAuraWindowTypeForWidgetType(Widget::InitParams::Type type) { | |
| 44 switch (type) { | |
| 45 case Widget::InitParams::TYPE_WINDOW: | |
| 46 return aura::WINDOW_TYPE_NORMAL; | |
| 47 case Widget::InitParams::TYPE_WINDOW_FRAMELESS: | |
| 48 case Widget::InitParams::TYPE_CONTROL: | |
| 49 case Widget::InitParams::TYPE_POPUP: | |
| 50 case Widget::InitParams::TYPE_BUBBLE: | |
| 51 return aura::WINDOW_TYPE_POPUP; | |
| 52 case Widget::InitParams::TYPE_MENU: | |
| 53 return aura::WINDOW_TYPE_MENU; | |
| 54 case Widget::InitParams::TYPE_TOOLTIP: | |
| 55 return aura::WINDOW_TYPE_TOOLTIP; | |
| 56 default: | |
| 57 NOTREACHED() << "Unhandled widget type " << type; | |
| 58 return aura::WINDOW_TYPE_UNKNOWN; | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 } // namespace | |
| 63 | |
| 64 // Used when SetInactiveRenderingDisabled() is invoked to track when active | |
| 65 // status changes in such a way that we should enable inactive rendering. | |
| 66 class NativeWidgetAura::DesktopObserverImpl : public aura::DesktopObserver { | |
| 67 public: | |
| 68 explicit DesktopObserverImpl(NativeWidgetAura* host) | |
| 69 : host_(host) { | |
| 70 aura::Desktop::GetInstance()->AddObserver(this); | |
| 71 } | |
| 72 | |
| 73 virtual ~DesktopObserverImpl() { | |
| 74 aura::Desktop::GetInstance()->RemoveObserver(this); | |
| 75 } | |
| 76 | |
| 77 // DesktopObserver overrides: | |
| 78 virtual void OnActiveWindowChanged(aura::Window* active) OVERRIDE { | |
| 79 if (!active || (active != host_->window_ && | |
| 80 active->transient_parent() != host_->window_)) { | |
| 81 host_->delegate_->EnableInactiveRendering(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 NativeWidgetAura* host_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(DesktopObserverImpl); | |
| 89 }; | |
| 90 | |
| 91 //////////////////////////////////////////////////////////////////////////////// | |
| 92 // NativeWidgetAura, public: | |
| 93 | |
| 94 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) | |
| 95 : delegate_(delegate), | |
| 96 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), | |
| 97 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | |
| 98 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), | |
| 99 can_activate_(true), | |
| 100 cursor_(gfx::kNullCursor) { | |
| 101 } | |
| 102 | |
| 103 NativeWidgetAura::~NativeWidgetAura() { | |
| 104 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | |
| 105 delete delegate_; | |
| 106 else | |
| 107 CloseNow(); | |
| 108 } | |
| 109 | |
| 110 // static | |
| 111 gfx::Font NativeWidgetAura::GetWindowTitleFont() { | |
| 112 #if defined(OS_WIN) | |
| 113 NONCLIENTMETRICS ncm; | |
| 114 base::win::GetNonClientMetrics(&ncm); | |
| 115 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); | |
| 116 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont))); | |
| 117 return gfx::Font(caption_font); | |
| 118 #else | |
| 119 return gfx::Font(); | |
| 120 #endif | |
| 121 } | |
| 122 | |
| 123 //////////////////////////////////////////////////////////////////////////////// | |
| 124 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: | |
| 125 | |
| 126 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { | |
| 127 ownership_ = params.ownership; | |
| 128 window_->set_user_data(this); | |
| 129 Widget::InitParams::Type window_type = | |
| 130 params.child ? Widget::InitParams::TYPE_CONTROL : params.type; | |
| 131 window_->SetType(GetAuraWindowTypeForWidgetType(window_type)); | |
| 132 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 133 window_->Init(params.create_texture_for_layer ? | |
| 134 ui::Layer::LAYER_HAS_TEXTURE : | |
| 135 ui::Layer::LAYER_HAS_NO_TEXTURE); | |
| 136 if (window_type == Widget::InitParams::TYPE_CONTROL) | |
| 137 window_->Show(); | |
| 138 | |
| 139 window_->layer()->SetFillsBoundsOpaquely(!params.transparent); | |
| 140 delegate_->OnNativeWidgetCreated(); | |
| 141 window_->SetBounds(params.bounds); | |
| 142 if (window_type == Widget::InitParams::TYPE_CONTROL) { | |
| 143 window_->SetParent(params.GetParent()); | |
| 144 } else { | |
| 145 // Set up the transient child before the window is added. This way the | |
| 146 // LayoutManager knows the window has a transient parent. | |
| 147 gfx::NativeView parent = params.GetParent(); | |
| 148 if (parent) | |
| 149 parent->AddTransientChild(window_); | |
| 150 // SetAlwaysOnTop before SetParent so that always-on-top container is used. | |
| 151 SetAlwaysOnTop(params.keep_on_top); | |
| 152 window_->SetParent(NULL); | |
| 153 } | |
| 154 window_->set_ignore_events(!params.accept_events); | |
| 155 // TODO(beng): do this some other way. | |
| 156 delegate_->OnNativeWidgetSizeChanged(params.bounds.size()); | |
| 157 can_activate_ = params.can_activate; | |
| 158 DCHECK(GetWidget()->GetRootView()); | |
| 159 if (params.type != Widget::InitParams::TYPE_TOOLTIP && !params.child) { | |
| 160 views::TooltipManagerViews* manager = new views::TooltipManagerViews( | |
| 161 GetWidget()->GetRootView()); | |
| 162 tooltip_manager_.reset(manager); | |
| 163 } | |
| 164 | |
| 165 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); | |
| 166 if (params.type != Widget::InitParams::TYPE_TOOLTIP && | |
| 167 params.type != Widget::InitParams::TYPE_POPUP) { | |
| 168 window_->SetProperty(aura::kDragDropDelegateKey, | |
| 169 static_cast<aura::WindowDragDropDelegate*>(this)); | |
| 170 } | |
| 171 | |
| 172 if (window_type == Widget::InitParams::TYPE_MENU) | |
| 173 window_->SetIntProperty(aura::kShadowTypeKey, | |
| 174 aura::SHADOW_TYPE_RECTANGULAR); | |
| 175 } | |
| 176 | |
| 177 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { | |
| 178 return NULL; | |
| 179 } | |
| 180 | |
| 181 void NativeWidgetAura::UpdateFrameAfterFrameChange() { | |
| 182 // We don't support changing the frame type. | |
| 183 NOTREACHED(); | |
| 184 } | |
| 185 | |
| 186 bool NativeWidgetAura::ShouldUseNativeFrame() const { | |
| 187 // There is only one frame type for aura. | |
| 188 return false; | |
| 189 } | |
| 190 | |
| 191 void NativeWidgetAura::FrameTypeChanged() { | |
| 192 // This is called when the Theme has changed; forward the event to the root | |
| 193 // widget. | |
| 194 GetWidget()->ThemeChanged(); | |
| 195 GetWidget()->GetRootView()->SchedulePaint(); | |
| 196 } | |
| 197 | |
| 198 Widget* NativeWidgetAura::GetWidget() { | |
| 199 return delegate_->AsWidget(); | |
| 200 } | |
| 201 | |
| 202 const Widget* NativeWidgetAura::GetWidget() const { | |
| 203 return delegate_->AsWidget(); | |
| 204 } | |
| 205 | |
| 206 gfx::NativeView NativeWidgetAura::GetNativeView() const { | |
| 207 return window_; | |
| 208 } | |
| 209 | |
| 210 gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { | |
| 211 return window_; | |
| 212 } | |
| 213 | |
| 214 Widget* NativeWidgetAura::GetTopLevelWidget() { | |
| 215 NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); | |
| 216 return native_widget ? native_widget->GetWidget() : NULL; | |
| 217 } | |
| 218 | |
| 219 const ui::Compositor* NativeWidgetAura::GetCompositor() const { | |
| 220 return window_->layer()->GetCompositor(); | |
| 221 } | |
| 222 | |
| 223 ui::Compositor* NativeWidgetAura::GetCompositor() { | |
| 224 return window_->layer()->GetCompositor(); | |
| 225 } | |
| 226 | |
| 227 void NativeWidgetAura::CalculateOffsetToAncestorWithLayer( | |
| 228 gfx::Point* offset, | |
| 229 ui::Layer** layer_parent) { | |
| 230 if (layer_parent) | |
| 231 *layer_parent = window_->layer(); | |
| 232 } | |
| 233 | |
| 234 void NativeWidgetAura::ReorderLayers() { | |
| 235 } | |
| 236 | |
| 237 void NativeWidgetAura::ViewRemoved(View* view) { | |
| 238 // DropTarget stuff. Most likely http://crbug.com/97845 | |
| 239 //NOTIMPLEMENTED(); | |
| 240 } | |
| 241 | |
| 242 void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { | |
| 243 if (window_) | |
| 244 window_->SetProperty(name, value); | |
| 245 } | |
| 246 | |
| 247 void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { | |
| 248 return window_ ? window_->GetProperty(name) : NULL; | |
| 249 } | |
| 250 | |
| 251 TooltipManager* NativeWidgetAura::GetTooltipManager() const { | |
| 252 return tooltip_manager_.get(); | |
| 253 } | |
| 254 | |
| 255 bool NativeWidgetAura::IsScreenReaderActive() const { | |
| 256 // http://crbug.com/102570 | |
| 257 //NOTIMPLEMENTED(); | |
| 258 return false; | |
| 259 } | |
| 260 | |
| 261 void NativeWidgetAura::SendNativeAccessibilityEvent( | |
| 262 View* view, | |
| 263 ui::AccessibilityTypes::Event event_type) { | |
| 264 // http://crbug.com/102570 | |
| 265 //NOTIMPLEMENTED(); | |
| 266 } | |
| 267 | |
| 268 void NativeWidgetAura::SetMouseCapture() { | |
| 269 window_->SetCapture(); | |
| 270 } | |
| 271 | |
| 272 void NativeWidgetAura::ReleaseMouseCapture() { | |
| 273 window_->ReleaseCapture(); | |
| 274 } | |
| 275 | |
| 276 bool NativeWidgetAura::HasMouseCapture() const { | |
| 277 return window_->HasCapture(); | |
| 278 } | |
| 279 | |
| 280 InputMethod* NativeWidgetAura::CreateInputMethod() { | |
| 281 #if defined(HAVE_IBUS) | |
| 282 InputMethod* input_method = new InputMethodIBus(this); | |
| 283 #else | |
| 284 InputMethod* input_method = new MockInputMethod(this); | |
| 285 #endif | |
| 286 input_method->Init(GetWidget()); | |
| 287 return input_method; | |
| 288 } | |
| 289 | |
| 290 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | |
| 291 const gfx::Rect parent_bounds = window_->parent()->bounds(); | |
| 292 window_->SetBounds(gfx::Rect((parent_bounds.width() - size.width())/2, | |
| 293 (parent_bounds.height() - size.height())/2, | |
| 294 size.width(), | |
| 295 size.height())); | |
| 296 } | |
| 297 | |
| 298 void NativeWidgetAura::GetWindowPlacement( | |
| 299 gfx::Rect* bounds, | |
| 300 ui::WindowShowState* show_state) const { | |
| 301 *bounds = window_->GetTargetBounds(); | |
| 302 *show_state = static_cast<ui::WindowShowState>( | |
| 303 window_->GetIntProperty(aura::kShowStateKey)); | |
| 304 } | |
| 305 | |
| 306 void NativeWidgetAura::SetWindowTitle(const string16& title) { | |
| 307 window_->set_title(title); | |
| 308 } | |
| 309 | |
| 310 void NativeWidgetAura::SetWindowIcons(const SkBitmap& window_icon, | |
| 311 const SkBitmap& app_icon) { | |
| 312 // Aura doesn't have window icons. | |
| 313 } | |
| 314 | |
| 315 void NativeWidgetAura::SetAccessibleName(const string16& name) { | |
| 316 // http://crbug.com/102570 | |
| 317 //NOTIMPLEMENTED(); | |
| 318 } | |
| 319 | |
| 320 void NativeWidgetAura::SetAccessibleRole(ui::AccessibilityTypes::Role role) { | |
| 321 // http://crbug.com/102570 | |
| 322 //NOTIMPLEMENTED(); | |
| 323 } | |
| 324 | |
| 325 void NativeWidgetAura::SetAccessibleState(ui::AccessibilityTypes::State state) { | |
| 326 // http://crbug.com/102570 | |
| 327 //NOTIMPLEMENTED(); | |
| 328 } | |
| 329 | |
| 330 void NativeWidgetAura::BecomeModal() { | |
| 331 window_->SetIntProperty(aura::kModalKey, 1); | |
| 332 } | |
| 333 | |
| 334 gfx::Rect NativeWidgetAura::GetWindowScreenBounds() const { | |
| 335 return window_->GetScreenBounds(); | |
| 336 } | |
| 337 | |
| 338 gfx::Rect NativeWidgetAura::GetClientAreaScreenBounds() const { | |
| 339 // In Aura, the entire window is the client area. | |
| 340 return window_->GetScreenBounds(); | |
| 341 } | |
| 342 | |
| 343 gfx::Rect NativeWidgetAura::GetRestoredBounds() const { | |
| 344 gfx::Rect* restore_bounds = reinterpret_cast<gfx::Rect*>( | |
| 345 window_->GetProperty(aura::kRestoreBoundsKey)); | |
| 346 return restore_bounds ? *restore_bounds : window_->bounds(); | |
| 347 } | |
| 348 | |
| 349 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { | |
| 350 window_->SetBounds(bounds); | |
| 351 } | |
| 352 | |
| 353 void NativeWidgetAura::SetSize(const gfx::Size& size) { | |
| 354 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); | |
| 355 } | |
| 356 | |
| 357 void NativeWidgetAura::MoveAbove(gfx::NativeView native_view) { | |
| 358 if (window_->parent() && window_->parent() == native_view->parent()) | |
| 359 window_->parent()->MoveChildAbove(window_, native_view); | |
| 360 } | |
| 361 | |
| 362 void NativeWidgetAura::MoveToTop() { | |
| 363 window_->parent()->MoveChildToFront(window_); | |
| 364 } | |
| 365 | |
| 366 void NativeWidgetAura::SetShape(gfx::NativeRegion region) { | |
| 367 // No need for this. | |
| 368 } | |
| 369 | |
| 370 void NativeWidgetAura::Close() { | |
| 371 // |window_| may already be deleted by parent window. This can happen | |
| 372 // when this widget is child widget or has transient parent | |
| 373 // and ownership is WIDGET_OWNS_NATIVE_WIDGET. | |
| 374 DCHECK(window_ || | |
| 375 ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); | |
| 376 if (window_) | |
| 377 Hide(); | |
| 378 | |
| 379 window_->SetIntProperty(aura::kModalKey, 0); | |
| 380 | |
| 381 if (!close_widget_factory_.HasWeakPtrs()) { | |
| 382 MessageLoop::current()->PostTask( | |
| 383 FROM_HERE, | |
| 384 base::Bind(&NativeWidgetAura::CloseNow, | |
| 385 close_widget_factory_.GetWeakPtr())); | |
| 386 } | |
| 387 } | |
| 388 | |
| 389 void NativeWidgetAura::CloseNow() { | |
| 390 delete window_; | |
| 391 } | |
| 392 | |
| 393 void NativeWidgetAura::EnableClose(bool enable) { | |
| 394 // http://crbug.com/102581 | |
| 395 NOTIMPLEMENTED(); | |
| 396 } | |
| 397 | |
| 398 void NativeWidgetAura::Show() { | |
| 399 ShowWithWindowState(ui::SHOW_STATE_INACTIVE); | |
| 400 } | |
| 401 | |
| 402 void NativeWidgetAura::Hide() { | |
| 403 window_->Hide(); | |
| 404 } | |
| 405 | |
| 406 void NativeWidgetAura::ShowMaximizedWithBounds( | |
| 407 const gfx::Rect& restored_bounds) { | |
| 408 window_->SetBounds(restored_bounds); | |
| 409 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); | |
| 410 } | |
| 411 | |
| 412 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { | |
| 413 if (state == ui::SHOW_STATE_MAXIMIZED || | |
| 414 state == ui::SHOW_STATE_FULLSCREEN) { | |
| 415 window_->SetIntProperty(aura::kShowStateKey, state); | |
| 416 } | |
| 417 window_->Show(); | |
| 418 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE || | |
| 419 !GetWidget()->SetInitialFocus())) { | |
| 420 window_->Activate(); | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 bool NativeWidgetAura::IsVisible() const { | |
| 425 return window_->IsVisible(); | |
| 426 } | |
| 427 | |
| 428 void NativeWidgetAura::Activate() { | |
| 429 window_->Activate(); | |
| 430 } | |
| 431 | |
| 432 void NativeWidgetAura::Deactivate() { | |
| 433 window_->Deactivate(); | |
| 434 } | |
| 435 | |
| 436 bool NativeWidgetAura::IsActive() const { | |
| 437 return aura::Desktop::GetInstance()->active_window() == window_; | |
| 438 } | |
| 439 | |
| 440 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { | |
| 441 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top); | |
| 442 } | |
| 443 | |
| 444 void NativeWidgetAura::Maximize() { | |
| 445 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 446 } | |
| 447 | |
| 448 void NativeWidgetAura::Minimize() { | |
| 449 // No minimized window for aura. crbug.com/104571. | |
| 450 NOTREACHED(); | |
| 451 } | |
| 452 | |
| 453 bool NativeWidgetAura::IsMaximized() const { | |
| 454 return window_->GetIntProperty(aura::kShowStateKey) == | |
| 455 ui::SHOW_STATE_MAXIMIZED; | |
| 456 } | |
| 457 | |
| 458 bool NativeWidgetAura::IsMinimized() const { | |
| 459 return window_->GetIntProperty(aura::kShowStateKey) == | |
| 460 ui::SHOW_STATE_MINIMIZED; | |
| 461 } | |
| 462 | |
| 463 void NativeWidgetAura::Restore() { | |
| 464 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 465 } | |
| 466 | |
| 467 void NativeWidgetAura::SetFullscreen(bool fullscreen) { | |
| 468 window_->SetIntProperty( | |
| 469 aura::kShowStateKey, | |
| 470 fullscreen ? ui::SHOW_STATE_FULLSCREEN : ui::SHOW_STATE_NORMAL); | |
| 471 } | |
| 472 | |
| 473 bool NativeWidgetAura::IsFullscreen() const { | |
| 474 return window_->GetIntProperty(aura::kShowStateKey) == | |
| 475 ui::SHOW_STATE_FULLSCREEN; | |
| 476 } | |
| 477 | |
| 478 void NativeWidgetAura::SetOpacity(unsigned char opacity) { | |
| 479 window_->layer()->SetOpacity(opacity / 255.0); | |
| 480 } | |
| 481 | |
| 482 void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { | |
| 483 NOTIMPLEMENTED(); | |
| 484 } | |
| 485 | |
| 486 bool NativeWidgetAura::IsAccessibleWidget() const { | |
| 487 // http://crbug.com/102570 | |
| 488 //NOTIMPLEMENTED(); | |
| 489 return false; | |
| 490 } | |
| 491 | |
| 492 void NativeWidgetAura::RunShellDrag(View* view, | |
| 493 const ui::OSExchangeData& data, | |
| 494 int operation) { | |
| 495 aura::DragDropClient* client = static_cast<aura::DragDropClient*>( | |
| 496 aura::Desktop::GetInstance()->GetProperty( | |
| 497 aura::kDesktopDragDropClientKey)); | |
| 498 if (client) | |
| 499 client->StartDragAndDrop(data, operation); | |
| 500 } | |
| 501 | |
| 502 void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { | |
| 503 if (window_) | |
| 504 window_->SchedulePaintInRect(rect); | |
| 505 } | |
| 506 | |
| 507 void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { | |
| 508 cursor_ = cursor; | |
| 509 aura::Desktop::GetInstance()->SetCursor(cursor); | |
| 510 } | |
| 511 | |
| 512 void NativeWidgetAura::ClearNativeFocus() { | |
| 513 if (window_ && window_->GetFocusManager()) | |
| 514 window_->GetFocusManager()->SetFocusedWindow(window_); | |
| 515 } | |
| 516 | |
| 517 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) { | |
| 518 // http://crbug.com/102572 | |
| 519 NOTIMPLEMENTED(); | |
| 520 } | |
| 521 | |
| 522 bool NativeWidgetAura::ConvertPointFromAncestor(const Widget* ancestor, | |
| 523 gfx::Point* point) const { | |
| 524 // http://crbug.com/102573 | |
| 525 NOTIMPLEMENTED(); | |
| 526 return false; | |
| 527 } | |
| 528 | |
| 529 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { | |
| 530 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); | |
| 531 } | |
| 532 | |
| 533 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { | |
| 534 if (!value) | |
| 535 desktop_observer_.reset(); | |
| 536 else | |
| 537 desktop_observer_.reset(new DesktopObserverImpl(this)); | |
| 538 } | |
| 539 | |
| 540 //////////////////////////////////////////////////////////////////////////////// | |
| 541 // NativeWidgetAura, views::InputMethodDelegate implementation: | |
| 542 | |
| 543 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) { | |
| 544 if (delegate_->OnKeyEvent(key)) | |
| 545 return; | |
| 546 if (key.type() == ui::ET_KEY_PRESSED && GetWidget()->GetFocusManager()) | |
| 547 GetWidget()->GetFocusManager()->OnKeyEvent(key); | |
| 548 } | |
| 549 | |
| 550 //////////////////////////////////////////////////////////////////////////////// | |
| 551 // NativeWidgetAura, aura::WindowDelegate implementation: | |
| 552 | |
| 553 void NativeWidgetAura::OnBoundsChanging(gfx::Rect* new_bounds) { | |
| 554 // Enforces a minimum size. | |
| 555 const gfx::Size& min_size = delegate_->GetMinimumSize(); | |
| 556 new_bounds->set_width(std::max(min_size.width(), new_bounds->width())); | |
| 557 new_bounds->set_height(std::max(min_size.height(), new_bounds->height())); | |
| 558 } | |
| 559 | |
| 560 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 561 const gfx::Rect& new_bounds) { | |
| 562 if (old_bounds.origin() != new_bounds.origin()) | |
| 563 GetWidget()->widget_delegate()->OnWidgetMove(); | |
| 564 if (old_bounds.size() != new_bounds.size()) | |
| 565 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); | |
| 566 } | |
| 567 | |
| 568 void NativeWidgetAura::OnFocus() { | |
| 569 Widget* widget = GetWidget(); | |
| 570 if (widget->is_top_level()) { | |
| 571 InputMethod* input_method = widget->GetInputMethod(); | |
| 572 input_method->OnFocus(); | |
| 573 // See description of got_initial_focus_in_ for details on this. | |
| 574 // TODO(mazda): Investigate this is actually necessary. | |
| 575 // widget->GetFocusManager()->RestoreFocusedView(); | |
| 576 } | |
| 577 delegate_->OnNativeFocus(window_); | |
| 578 } | |
| 579 | |
| 580 void NativeWidgetAura::OnBlur() { | |
| 581 Widget* widget = GetWidget(); | |
| 582 if (widget->is_top_level()) { | |
| 583 InputMethod* input_method = widget->GetInputMethod(); | |
| 584 input_method->OnBlur(); | |
| 585 widget->GetFocusManager()->StoreFocusedView(); | |
| 586 } | |
| 587 delegate_->OnNativeBlur(NULL); | |
| 588 } | |
| 589 | |
| 590 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { | |
| 591 // TODO(beng): Need an InputMethodAura to properly handle character events. | |
| 592 // Right now, we just skip these. | |
| 593 if (event->is_char()) | |
| 594 return false; | |
| 595 | |
| 596 DCHECK(window_->IsVisible()); | |
| 597 InputMethod* input_method = GetWidget()->GetInputMethod(); | |
| 598 DCHECK(input_method); | |
| 599 // TODO(oshima): DispatchKeyEvent should return bool? | |
| 600 KeyEvent views_event(event); | |
| 601 input_method->DispatchKeyEvent(views_event); | |
| 602 return true; | |
| 603 } | |
| 604 | |
| 605 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { | |
| 606 return cursor_; | |
| 607 } | |
| 608 | |
| 609 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { | |
| 610 return delegate_->GetNonClientComponent(point); | |
| 611 } | |
| 612 | |
| 613 bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) { | |
| 614 DCHECK(window_->IsVisible()); | |
| 615 if (event->type() == ui::ET_MOUSEWHEEL) { | |
| 616 MouseWheelEvent wheel_event(event); | |
| 617 if (tooltip_manager_.get()) | |
| 618 tooltip_manager_->UpdateForMouseEvent(wheel_event); | |
| 619 return delegate_->OnMouseEvent(wheel_event); | |
| 620 } | |
| 621 MouseEvent mouse_event(event); | |
| 622 if (tooltip_manager_.get()) | |
| 623 tooltip_manager_->UpdateForMouseEvent(mouse_event); | |
| 624 return delegate_->OnMouseEvent(mouse_event); | |
| 625 } | |
| 626 | |
| 627 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) { | |
| 628 DCHECK(window_->IsVisible()); | |
| 629 TouchEvent touch_event(event); | |
| 630 return delegate_->OnTouchEvent(touch_event); | |
| 631 } | |
| 632 | |
| 633 bool NativeWidgetAura::ShouldActivate(aura::Event* event) { | |
| 634 return can_activate_; | |
| 635 } | |
| 636 | |
| 637 void NativeWidgetAura::OnActivated() { | |
| 638 delegate_->OnNativeWidgetActivationChanged(true); | |
| 639 if (IsVisible() && GetWidget()->non_client_view()) | |
| 640 GetWidget()->non_client_view()->SchedulePaint(); | |
| 641 } | |
| 642 | |
| 643 void NativeWidgetAura::OnLostActive() { | |
| 644 delegate_->OnNativeWidgetActivationChanged(false); | |
| 645 if (IsVisible() && GetWidget()->non_client_view()) | |
| 646 GetWidget()->non_client_view()->SchedulePaint(); | |
| 647 } | |
| 648 | |
| 649 void NativeWidgetAura::OnCaptureLost() { | |
| 650 delegate_->OnMouseCaptureLost(); | |
| 651 } | |
| 652 | |
| 653 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) { | |
| 654 delegate_->OnNativeWidgetPaint(canvas); | |
| 655 } | |
| 656 | |
| 657 void NativeWidgetAura::OnWindowDestroying() { | |
| 658 window_->SetProperty(aura::kDragDropDelegateKey, NULL); | |
| 659 delegate_->OnNativeWidgetDestroying(); | |
| 660 | |
| 661 // If the aura::Window is destroyed, we can no longer show tooltips. | |
| 662 tooltip_manager_.reset(); | |
| 663 } | |
| 664 | |
| 665 void NativeWidgetAura::OnWindowDestroyed() { | |
| 666 window_ = NULL; | |
| 667 tooltip_manager_.reset(); | |
| 668 delegate_->OnNativeWidgetDestroyed(); | |
| 669 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | |
| 670 delete this; | |
| 671 } | |
| 672 | |
| 673 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) { | |
| 674 delegate_->OnNativeWidgetVisibilityChanged(visible); | |
| 675 } | |
| 676 | |
| 677 bool NativeWidgetAura::CanDrop(const aura::DropTargetEvent& event) { | |
| 678 DCHECK(drop_helper_.get() != NULL); | |
| 679 View* view = drop_helper_->target_view(); | |
| 680 if (view) | |
| 681 return view->CanDrop(event.data()); | |
| 682 return false; | |
| 683 } | |
| 684 | |
| 685 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) { | |
| 686 DCHECK(drop_helper_.get() != NULL); | |
| 687 drop_helper_->OnDragOver(event.data(), event.location(), | |
| 688 event.source_operations()); | |
| 689 } | |
| 690 | |
| 691 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) { | |
| 692 DCHECK(drop_helper_.get() != NULL); | |
| 693 return drop_helper_->OnDragOver(event.data(), event.location(), | |
| 694 event.source_operations()); | |
| 695 } | |
| 696 | |
| 697 void NativeWidgetAura::OnDragExited() { | |
| 698 DCHECK(drop_helper_.get() != NULL); | |
| 699 drop_helper_->OnDragExit(); | |
| 700 } | |
| 701 | |
| 702 int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) { | |
| 703 DCHECK(drop_helper_.get() != NULL); | |
| 704 return drop_helper_->OnDrop(event.data(), event.location(), | |
| 705 event.source_operations()); | |
| 706 } | |
| 707 | |
| 708 //////////////////////////////////////////////////////////////////////////////// | |
| 709 // Widget, public: | |
| 710 | |
| 711 // static | |
| 712 void Widget::NotifyLocaleChanged() { | |
| 713 // http://crbug.com/102574 | |
| 714 NOTIMPLEMENTED(); | |
| 715 } | |
| 716 | |
| 717 // static | |
| 718 void Widget::CloseAllSecondaryWidgets() { | |
| 719 // http://crbug.com/102575 | |
| 720 NOTIMPLEMENTED(); | |
| 721 } | |
| 722 | |
| 723 bool Widget::ConvertRect(const Widget* source, | |
| 724 const Widget* target, | |
| 725 gfx::Rect* rect) { | |
| 726 return false; | |
| 727 } | |
| 728 | |
| 729 namespace internal { | |
| 730 | |
| 731 //////////////////////////////////////////////////////////////////////////////// | |
| 732 // internal::NativeWidgetPrivate, public: | |
| 733 | |
| 734 // static | |
| 735 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget( | |
| 736 internal::NativeWidgetDelegate* delegate) { | |
| 737 return new NativeWidgetAura(delegate); | |
| 738 } | |
| 739 | |
| 740 // static | |
| 741 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( | |
| 742 gfx::NativeView native_view) { | |
| 743 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data()); | |
| 744 } | |
| 745 | |
| 746 // static | |
| 747 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( | |
| 748 gfx::NativeWindow native_window) { | |
| 749 return reinterpret_cast<NativeWidgetAura*>(native_window->user_data()); | |
| 750 } | |
| 751 | |
| 752 // static | |
| 753 NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( | |
| 754 gfx::NativeView native_view) { | |
| 755 aura::Window* window = native_view; | |
| 756 NativeWidgetPrivate* top_level_native_widget = NULL; | |
| 757 while (window) { | |
| 758 NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window); | |
| 759 if (native_widget) | |
| 760 top_level_native_widget = native_widget; | |
| 761 window = window->parent(); | |
| 762 } | |
| 763 return top_level_native_widget; | |
| 764 } | |
| 765 | |
| 766 // static | |
| 767 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, | |
| 768 Widget::Widgets* children) { | |
| 769 { | |
| 770 // Code expects widget for |native_view| to be added to |children|. | |
| 771 NativeWidgetAura* native_widget = static_cast<NativeWidgetAura*>( | |
| 772 GetNativeWidgetForNativeView(native_view)); | |
| 773 if (native_widget->GetWidget()) | |
| 774 children->insert(native_widget->GetWidget()); | |
| 775 } | |
| 776 | |
| 777 const aura::Window::Windows& child_windows = native_view->children(); | |
| 778 for (aura::Window::Windows::const_iterator i = child_windows.begin(); | |
| 779 i != child_windows.end(); ++i) { | |
| 780 NativeWidgetAura* native_widget = | |
| 781 static_cast<NativeWidgetAura*>(GetNativeWidgetForNativeView(*i)); | |
| 782 if (native_widget) | |
| 783 children->insert(native_widget->GetWidget()); | |
| 784 } | |
| 785 } | |
| 786 | |
| 787 // static | |
| 788 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, | |
| 789 gfx::NativeView new_parent) { | |
| 790 // http://crbug.com/102576 | |
| 791 NOTIMPLEMENTED(); | |
| 792 } | |
| 793 | |
| 794 // static | |
| 795 bool NativeWidgetPrivate::IsMouseButtonDown() { | |
| 796 return aura::Desktop::GetInstance()->IsMouseButtonDown(); | |
| 797 } | |
| 798 | |
| 799 } // namespace internal | |
| 800 } // namespace views | |
| OLD | NEW |