| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "ui/aura/client/activation_client.h" | 9 #include "ui/aura/client/activation_client.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/client/drag_drop_client.h" | 11 #include "ui/aura/client/drag_drop_client.h" |
| 12 #include "ui/aura/client/window_types.h" | 12 #include "ui/aura/client/window_types.h" |
| 13 #include "ui/aura/event.h" | 13 #include "ui/aura/event.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 17 #include "ui/base/dragdrop/os_exchange_data.h" | 17 #include "ui/base/dragdrop/os_exchange_data.h" |
| 18 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/compositor/layer.h" | 20 #include "ui/gfx/compositor/layer.h" |
| 21 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
| 22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 23 #include "ui/views/ime/input_method_bridge.h" |
| 23 #include "ui/views/widget/drop_helper.h" | 24 #include "ui/views/widget/drop_helper.h" |
| 24 #include "ui/views/widget/native_widget_delegate.h" | 25 #include "ui/views/widget/native_widget_delegate.h" |
| 25 #include "ui/views/widget/tooltip_manager_aura.h" | 26 #include "ui/views/widget/tooltip_manager_aura.h" |
| 26 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
| 27 | 28 |
| 28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 29 #include "base/win/scoped_gdi_object.h" | 30 #include "base/win/scoped_gdi_object.h" |
| 30 #include "base/win/win_util.h" | 31 #include "base/win/win_util.h" |
| 31 #include "ui/base/l10n/l10n_util_win.h" | 32 #include "ui/base/l10n/l10n_util_win.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 #if defined(HAVE_IBUS) | |
| 35 #include "ui/views/ime/input_method_ibus.h" | |
| 36 #else | |
| 37 #include "ui/views/ime/mock_input_method.h" | |
| 38 #endif | |
| 39 | |
| 40 namespace views { | 35 namespace views { |
| 41 | 36 |
| 42 namespace { | 37 namespace { |
| 43 | 38 |
| 44 aura::client::WindowType GetAuraWindowTypeForWidgetType( | 39 aura::client::WindowType GetAuraWindowTypeForWidgetType( |
| 45 Widget::InitParams::Type type) { | 40 Widget::InitParams::Type type) { |
| 46 switch (type) { | 41 switch (type) { |
| 47 case Widget::InitParams::TYPE_WINDOW: | 42 case Widget::InitParams::TYPE_WINDOW: |
| 48 return aura::client::WINDOW_TYPE_NORMAL; | 43 return aura::client::WINDOW_TYPE_NORMAL; |
| 49 case Widget::InitParams::TYPE_WINDOW_FRAMELESS: | 44 case Widget::InitParams::TYPE_WINDOW_FRAMELESS: |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 299 |
| 305 void NativeWidgetAura::ReleaseMouseCapture() { | 300 void NativeWidgetAura::ReleaseMouseCapture() { |
| 306 window_->ReleaseCapture(); | 301 window_->ReleaseCapture(); |
| 307 } | 302 } |
| 308 | 303 |
| 309 bool NativeWidgetAura::HasMouseCapture() const { | 304 bool NativeWidgetAura::HasMouseCapture() const { |
| 310 return window_->HasCapture(); | 305 return window_->HasCapture(); |
| 311 } | 306 } |
| 312 | 307 |
| 313 InputMethod* NativeWidgetAura::CreateInputMethod() { | 308 InputMethod* NativeWidgetAura::CreateInputMethod() { |
| 314 #if defined(HAVE_IBUS) | 309 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
| 315 InputMethod* input_method = new InputMethodIBus(this); | 310 ui::InputMethod* host = reinterpret_cast<ui::InputMethod*>( |
| 316 #else | 311 root_window->GetProperty(aura::client::kRootWindowInputMethod)); |
| 317 InputMethod* input_method = new MockInputMethod(this); | 312 InputMethod* input_method = new InputMethodBridge(this, host); |
| 318 #endif | |
| 319 input_method->Init(GetWidget()); | 313 input_method->Init(GetWidget()); |
| 320 return input_method; | 314 return input_method; |
| 321 } | 315 } |
| 322 | 316 |
| 323 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { | 317 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { |
| 324 const gfx::Rect parent_bounds = window_->parent()->bounds(); | 318 const gfx::Rect parent_bounds = window_->parent()->bounds(); |
| 325 window_->SetBounds(gfx::Rect((parent_bounds.width() - size.width())/2, | 319 window_->SetBounds(gfx::Rect((parent_bounds.width() - size.width())/2, |
| 326 (parent_bounds.height() - size.height())/2, | 320 (parent_bounds.height() - size.height())/2, |
| 327 size.width(), | 321 size.width(), |
| 328 size.height())); | 322 size.height())); |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 void NativeWidgetAura::OnBlur() { | 624 void NativeWidgetAura::OnBlur() { |
| 631 Widget* widget = GetWidget(); | 625 Widget* widget = GetWidget(); |
| 632 if (widget->is_top_level()) { | 626 if (widget->is_top_level()) { |
| 633 InputMethod* input_method = widget->GetInputMethod(); | 627 InputMethod* input_method = widget->GetInputMethod(); |
| 634 input_method->OnBlur(); | 628 input_method->OnBlur(); |
| 635 } | 629 } |
| 636 delegate_->OnNativeBlur(NULL); | 630 delegate_->OnNativeBlur(NULL); |
| 637 } | 631 } |
| 638 | 632 |
| 639 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { | 633 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) { |
| 640 // TODO(beng): Need an InputMethodAura to properly handle character events. | 634 if (event->is_char()) { |
| 641 // Right now, we just skip these. | 635 // If a ui::InputMethod object is attched to the root window, character |
| 642 if (event->is_char()) | 636 // events are handled inside the object and are not passed to this function. |
| 637 // If such object is not attached, character events might be sent (e.g. on |
| 638 // Windows). In this case, we just skip these. |
| 643 return false; | 639 return false; |
| 640 } |
| 644 | 641 |
| 645 DCHECK(window_->IsVisible()); | 642 DCHECK(window_->IsVisible()); |
| 646 InputMethod* input_method = GetWidget()->GetInputMethod(); | 643 InputMethod* input_method = GetWidget()->GetInputMethod(); |
| 647 DCHECK(input_method); | 644 DCHECK(input_method); |
| 648 // TODO(oshima): DispatchKeyEvent should return bool? | |
| 649 KeyEvent views_event(event); | 645 KeyEvent views_event(event); |
| 650 input_method->DispatchKeyEvent(views_event); | 646 input_method->DispatchKeyEvent(views_event); |
| 651 return true; | 647 return true; |
| 652 } | 648 } |
| 653 | 649 |
| 654 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { | 650 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { |
| 655 return cursor_; | 651 return cursor_; |
| 656 } | 652 } |
| 657 | 653 |
| 658 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { | 654 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 } | 860 } |
| 865 } | 861 } |
| 866 | 862 |
| 867 // static | 863 // static |
| 868 bool NativeWidgetPrivate::IsMouseButtonDown() { | 864 bool NativeWidgetPrivate::IsMouseButtonDown() { |
| 869 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); | 865 return aura::RootWindow::GetInstance()->IsMouseButtonDown(); |
| 870 } | 866 } |
| 871 | 867 |
| 872 } // namespace internal | 868 } // namespace internal |
| 873 } // namespace views | 869 } // namespace views |
| OLD | NEW |