| 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 "chrome/browser/renderer_host/render_widget_host_view_views.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 } // namespace | 78 } // namespace |
| 79 | 79 |
| 80 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) | 80 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) |
| 81 : host_(host), | 81 : host_(host), |
| 82 about_to_validate_and_paint_(false), | 82 about_to_validate_and_paint_(false), |
| 83 is_hidden_(false), | 83 is_hidden_(false), |
| 84 is_loading_(false), | 84 is_loading_(false), |
| 85 native_cursor_(NULL), | 85 native_cursor_(NULL), |
| 86 is_showing_popup_menu_(false), | 86 is_showing_context_menu_(false), |
| 87 visually_deemphasized_(false), | 87 visually_deemphasized_(false), |
| 88 touch_event_(), | 88 touch_event_(), |
| 89 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 89 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 90 has_composition_text_(false) { | 90 has_composition_text_(false) { |
| 91 set_focusable(true); | 91 set_focusable(true); |
| 92 host_->SetView(this); | 92 host_->SetView(this); |
| 93 } | 93 } |
| 94 | 94 |
| 95 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { | 95 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { |
| 96 } | 96 } |
| 97 | 97 |
| 98 void RenderWidgetHostViewViews::InitAsChild() { | 98 void RenderWidgetHostViewViews::InitAsChild() { |
| 99 Show(); | 99 Show(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void RenderWidgetHostViewViews::InitAsPopup( | 102 void RenderWidgetHostViewViews::InitAsPopup( |
| 103 RenderWidgetHostView* parent_host_view, | 103 RenderWidgetHostView* parent_host_view, |
| 104 const gfx::Rect& pos) { | 104 const gfx::Rect& pos) { |
| 105 RenderWidgetHostViewViews* parent = | 105 RenderWidgetHostViewViews* parent = |
| 106 static_cast<RenderWidgetHostViewViews*>(parent_host_view); | 106 static_cast<RenderWidgetHostViewViews*>(parent_host_view); |
| 107 parent->AddChildView(this); | 107 parent->AddChildView(this); |
| 108 // If the parent loses focus then the popup will close. So we need | 108 // If the parent loses focus then the popup will close. So we need |
| 109 // to tell the parent it's showing a popup so that it doesn't respond to | 109 // to tell the parent it's showing a popup so that it doesn't respond to |
| 110 // blurs. | 110 // blurs. |
| 111 parent->is_showing_popup_menu_ = true; | 111 parent->is_showing_context_menu_ = true; |
| 112 views::View* root_view = GetWidget()->GetRootView(); | 112 views::View* root_view = GetWidget()->GetRootView(); |
| 113 // TODO(fsamuel): WebKit is computing the screen coordinates incorrectly. | 113 // TODO(fsamuel): WebKit is computing the screen coordinates incorrectly. |
| 114 // Fixing this is a long and involved process, because WebKit needs to know | 114 // Fixing this is a long and involved process, because WebKit needs to know |
| 115 // how to direct an IPC at a particular View. For now, we simply convert | 115 // how to direct an IPC at a particular View. For now, we simply convert |
| 116 // the broken screen coordinates into relative coordinates. | 116 // the broken screen coordinates into relative coordinates. |
| 117 gfx::Point p(pos.x() - root_view->GetScreenBounds().x(), | 117 gfx::Point p(pos.x() - root_view->GetScreenBounds().x(), |
| 118 pos.y() - root_view->GetScreenBounds().y()); | 118 pos.y() - root_view->GetScreenBounds().y()); |
| 119 views::View::SetBounds(p.x(), p.y(), pos.width(), pos.height()); | 119 views::View::SetBounds(p.x(), p.y(), pos.width(), pos.height()); |
| 120 Show(); | 120 Show(); |
| 121 | 121 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 host_->ViewDestroyed(); | 277 host_->ViewDestroyed(); |
| 278 Destroy(); | 278 Destroy(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void RenderWidgetHostViewViews::Destroy() { | 281 void RenderWidgetHostViewViews::Destroy() { |
| 282 // host_'s destruction brought us here, null it out so we don't use it | 282 // host_'s destruction brought us here, null it out so we don't use it |
| 283 host_ = NULL; | 283 host_ = NULL; |
| 284 if (parent()) { | 284 if (parent()) { |
| 285 if (IsPopup()) { | 285 if (IsPopup()) { |
| 286 static_cast<RenderWidgetHostViewViews*> | 286 static_cast<RenderWidgetHostViewViews*> |
| 287 (parent())->is_showing_popup_menu_ = false; | 287 (parent())->is_showing_context_menu_ = false; |
| 288 // We're hiding the popup so we need to make sure we repaint | 288 // We're hiding the popup so we need to make sure we repaint |
| 289 // what's underneath. | 289 // what's underneath. |
| 290 parent()->SchedulePaintInRect(bounds()); | 290 parent()->SchedulePaintInRect(bounds()); |
| 291 } | 291 } |
| 292 parent()->RemoveChildView(this); | 292 parent()->RemoveChildView(this); |
| 293 } | 293 } |
| 294 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 294 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void RenderWidgetHostViewViews::SetTooltipText(const std::wstring& tip) { | 297 void RenderWidgetHostViewViews::SetTooltipText(const std::wstring& tip) { |
| 298 const int kMaxTooltipLength = 8 << 10; | 298 const int kMaxTooltipLength = 8 << 10; |
| 299 // Clamp the tooltip length to kMaxTooltipLength so that we don't | 299 // Clamp the tooltip length to kMaxTooltipLength so that we don't |
| 300 // accidentally DOS the user with a mega tooltip. | 300 // accidentally DOS the user with a mega tooltip. |
| 301 tooltip_text_ = | 301 tooltip_text_ = |
| 302 l10n_util::TruncateString(WideToUTF16Hack(tip), kMaxTooltipLength); | 302 l10n_util::TruncateString(WideToUTF16Hack(tip), kMaxTooltipLength); |
| 303 if (GetWidget()) | 303 if (GetWidget()) |
| 304 GetWidget()->TooltipTextChanged(this); | 304 GetWidget()->TooltipTextChanged(this); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, | 307 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, |
| 308 const ui::Range& range) { | 308 const ui::Range& range) { |
| 309 // TODO(anicolao): deal with the clipboard without GTK | 309 // TODO(anicolao): deal with the clipboard without GTK |
| 310 NOTIMPLEMENTED(); | 310 NOTIMPLEMENTED(); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { | 313 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { |
| 314 is_showing_popup_menu_ = showing; | 314 is_showing_context_menu_ = showing; |
| 315 } | 315 } |
| 316 | 316 |
| 317 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 317 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
| 318 const gfx::Size& size) { | 318 const gfx::Size& size) { |
| 319 return new BackingStoreSkia(host_, size); | 319 return new BackingStoreSkia(host_, size); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { | 322 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { |
| 323 RenderWidgetHostView::SetBackground(background); | 323 RenderWidgetHostView::SetBackground(background); |
| 324 if (host_) | 324 if (host_) |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 host_->GotFocus(); | 670 host_->GotFocus(); |
| 671 host_->SetInputMethodActive(GetInputMethod()->IsActive()); | 671 host_->SetInputMethodActive(GetInputMethod()->IsActive()); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void RenderWidgetHostViewViews::OnBlur() { | 674 void RenderWidgetHostViewViews::OnBlur() { |
| 675 if (!host_) | 675 if (!host_) |
| 676 return; | 676 return; |
| 677 View::OnBlur(); | 677 View::OnBlur(); |
| 678 // If we are showing a context menu, maintain the illusion that webkit has | 678 // If we are showing a context menu, maintain the illusion that webkit has |
| 679 // focus. | 679 // focus. |
| 680 if (!is_showing_popup_menu_ && !is_hidden_) | 680 if (!is_showing_context_menu_ && !is_hidden_) |
| 681 host_->Blur(); | 681 host_->Blur(); |
| 682 host_->SetInputMethodActive(false); | 682 host_->SetInputMethodActive(false); |
| 683 } | 683 } |
| 684 | 684 |
| 685 bool RenderWidgetHostViewViews::NeedsInputGrab() { | 685 bool RenderWidgetHostViewViews::NeedsInputGrab() { |
| 686 return popup_type_ == WebKit::WebPopupTypeSelect; | 686 return popup_type_ == WebKit::WebPopupTypeSelect; |
| 687 } | 687 } |
| 688 | 688 |
| 689 bool RenderWidgetHostViewViews::IsPopup() { | 689 bool RenderWidgetHostViewViews::IsPopup() { |
| 690 return popup_type_ != WebKit::WebPopupTypeNone; | 690 return popup_type_ != WebKit::WebPopupTypeNone; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 715 | 715 |
| 716 void RenderWidgetHostViewViews::FinishImeCompositionSession() { | 716 void RenderWidgetHostViewViews::FinishImeCompositionSession() { |
| 717 if (!has_composition_text_) | 717 if (!has_composition_text_) |
| 718 return; | 718 return; |
| 719 if (host_) | 719 if (host_) |
| 720 host_->ImeConfirmComposition(); | 720 host_->ImeConfirmComposition(); |
| 721 DCHECK(GetInputMethod()); | 721 DCHECK(GetInputMethod()); |
| 722 GetInputMethod()->CancelComposition(this); | 722 GetInputMethod()->CancelComposition(this); |
| 723 has_composition_text_ = false; | 723 has_composition_text_ = false; |
| 724 } | 724 } |
| OLD | NEW |