Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 #include <gtk/gtkwindow.h> | 36 #include <gtk/gtkwindow.h> |
| 37 #include <gdk/gdkx.h> | 37 #include <gdk/gdkx.h> |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #if defined(TOUCH_UI) | 40 #if defined(TOUCH_UI) |
| 41 #include "chrome/browser/renderer_host/accelerated_surface_container_touch.h" | 41 #include "chrome/browser/renderer_host/accelerated_surface_container_touch.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 static const int kMaxWindowWidth = 4000; | 44 static const int kMaxWindowWidth = 4000; |
| 45 static const int kMaxWindowHeight = 4000; | 45 static const int kMaxWindowHeight = 4000; |
| 46 static const int kTouchControllerUpdateDelay = 150; | |
| 46 | 47 |
| 47 // static | 48 // static |
| 48 const char RenderWidgetHostViewViews::kViewClassName[] = | 49 const char RenderWidgetHostViewViews::kViewClassName[] = |
| 49 "browser/renderer_host/RenderWidgetHostViewViews"; | 50 "browser/renderer_host/RenderWidgetHostViewViews"; |
| 50 | 51 |
| 51 using WebKit::WebInputEventFactory; | 52 using WebKit::WebInputEventFactory; |
| 52 using WebKit::WebMouseWheelEvent; | 53 using WebKit::WebMouseWheelEvent; |
| 53 using WebKit::WebTouchEvent; | 54 using WebKit::WebTouchEvent; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 about_to_validate_and_paint_(false), | 89 about_to_validate_and_paint_(false), |
| 89 is_hidden_(false), | 90 is_hidden_(false), |
| 90 is_loading_(false), | 91 is_loading_(false), |
| 91 native_cursor_(NULL), | 92 native_cursor_(NULL), |
| 92 is_showing_context_menu_(false), | 93 is_showing_context_menu_(false), |
| 93 visually_deemphasized_(false), | 94 visually_deemphasized_(false), |
| 94 touch_event_(), | 95 touch_event_(), |
| 95 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 96 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 96 has_composition_text_(false), | 97 has_composition_text_(false), |
| 97 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_( | 98 ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_( |
| 98 views::TouchSelectionController::create(this))) { | 99 views::TouchSelectionController::create(this))), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST(update_touch_selection_(this)) { | |
| 99 set_focusable(true); | 101 set_focusable(true); |
| 100 host_->SetView(this); | 102 host_->SetView(this); |
| 101 | 103 |
| 102 #if defined(TOUCH_UI) | 104 #if defined(TOUCH_UI) |
| 103 SetPaintToLayer(true); | 105 SetPaintToLayer(true); |
| 104 SetFillsBoundsOpaquely(true); | 106 SetFillsBoundsOpaquely(true); |
| 105 #endif | 107 #endif |
| 106 } | 108 } |
| 107 | 109 |
| 108 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { | 110 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 void RenderWidgetHostViewViews::DidBecomeSelected() { | 145 void RenderWidgetHostViewViews::DidBecomeSelected() { |
| 144 if (!is_hidden_) | 146 if (!is_hidden_) |
| 145 return; | 147 return; |
| 146 | 148 |
| 147 if (tab_switch_paint_time_.is_null()) | 149 if (tab_switch_paint_time_.is_null()) |
| 148 tab_switch_paint_time_ = base::TimeTicks::Now(); | 150 tab_switch_paint_time_ = base::TimeTicks::Now(); |
| 149 is_hidden_ = false; | 151 is_hidden_ = false; |
| 150 if (host_) | 152 if (host_) |
| 151 host_->WasRestored(); | 153 host_->WasRestored(); |
| 152 | 154 |
| 153 if (touch_selection_controller_.get()) { | 155 UpdateTouchSelectionController(); |
| 154 touch_selection_controller_->SelectionChanged(selection_start_, | |
| 155 selection_end_); | |
| 156 } | |
| 157 } | 156 } |
| 158 | 157 |
| 159 void RenderWidgetHostViewViews::WasHidden() { | 158 void RenderWidgetHostViewViews::WasHidden() { |
| 160 if (is_hidden_) | 159 if (is_hidden_) |
| 161 return; | 160 return; |
| 162 | 161 |
| 163 // If we receive any more paint messages while we are hidden, we want to | 162 // If we receive any more paint messages while we are hidden, we want to |
| 164 // ignore them so we don't re-allocate the backing store. We will paint | 163 // ignore them so we don't re-allocate the backing store. We will paint |
| 165 // everything again when we become selected again. | 164 // everything again when we become selected again. |
| 166 is_hidden_ = true; | 165 is_hidden_ = true; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 } | 332 } |
| 334 | 333 |
| 335 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, | 334 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, |
| 336 const ui::Range& range, | 335 const ui::Range& range, |
| 337 const gfx::Point& start, | 336 const gfx::Point& start, |
| 338 const gfx::Point& end) { | 337 const gfx::Point& end) { |
| 339 // TODO(anicolao): deal with the clipboard without GTK | 338 // TODO(anicolao): deal with the clipboard without GTK |
| 340 NOTIMPLEMENTED(); | 339 NOTIMPLEMENTED(); |
| 341 selection_start_ = start; | 340 selection_start_ = start; |
| 342 selection_end_ = end; | 341 selection_end_ = end; |
| 343 if (touch_selection_controller_.get()) | 342 |
| 344 touch_selection_controller_->SelectionChanged(start, end); | 343 // Webkit can send spurious selection-change on text-input (e.g. when |
|
rjkroege
2011/09/02 19:15:25
So per our discussion, this is a temporary fix pen
sadrul
2011/09/02 19:39:44
Yep. Done
| |
| 344 // inserting text at the beginning of a non-empty text control). But in those | |
| 345 // cases, it does send the correct selection information quickly afterwards. | |
| 346 // So delay the notification to the touch-selection controller. | |
| 347 if (update_touch_selection_.empty()) { | |
| 348 MessageLoop::current()->PostDelayedTask(FROM_HERE, | |
| 349 update_touch_selection_.NewRunnableMethod( | |
| 350 &RenderWidgetHostViewViews::UpdateTouchSelectionController), | |
| 351 kTouchControllerUpdateDelay); | |
| 352 } | |
| 345 } | 353 } |
| 346 | 354 |
| 347 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { | 355 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { |
| 348 is_showing_context_menu_ = showing; | 356 is_showing_context_menu_ = showing; |
| 349 } | 357 } |
| 350 | 358 |
| 351 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 359 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
| 352 const gfx::Size& size) { | 360 const gfx::Size& size) { |
| 353 return new BackingStoreSkia(host_, size); | 361 return new BackingStoreSkia(host_, size); |
| 354 } | 362 } |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 | 811 |
| 804 void RenderWidgetHostViewViews::FinishImeCompositionSession() { | 812 void RenderWidgetHostViewViews::FinishImeCompositionSession() { |
| 805 if (!has_composition_text_) | 813 if (!has_composition_text_) |
| 806 return; | 814 return; |
| 807 if (host_) | 815 if (host_) |
| 808 host_->ImeConfirmComposition(); | 816 host_->ImeConfirmComposition(); |
| 809 DCHECK(GetInputMethod()); | 817 DCHECK(GetInputMethod()); |
| 810 GetInputMethod()->CancelComposition(this); | 818 GetInputMethod()->CancelComposition(this); |
| 811 has_composition_text_ = false; | 819 has_composition_text_ = false; |
| 812 } | 820 } |
| 821 | |
| 822 void RenderWidgetHostViewViews::UpdateTouchSelectionController() { | |
| 823 if (touch_selection_controller_.get()) | |
| 824 touch_selection_controller_->SelectionChanged(selection_start_, | |
| 825 selection_end_); | |
| 826 } | |
| OLD | NEW |