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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void RenderWidgetHostViewViews::DidBecomeSelected() { | 151 void RenderWidgetHostViewViews::DidBecomeSelected() { |
150 if (!is_hidden_) | 152 if (!is_hidden_) |
151 return; | 153 return; |
152 | 154 |
153 if (tab_switch_paint_time_.is_null()) | 155 if (tab_switch_paint_time_.is_null()) |
154 tab_switch_paint_time_ = base::TimeTicks::Now(); | 156 tab_switch_paint_time_ = base::TimeTicks::Now(); |
155 is_hidden_ = false; | 157 is_hidden_ = false; |
156 if (host_) | 158 if (host_) |
157 host_->WasRestored(); | 159 host_->WasRestored(); |
158 | 160 |
159 if (touch_selection_controller_.get()) { | 161 UpdateTouchSelectionController(); |
160 touch_selection_controller_->SelectionChanged(selection_start_, | |
161 selection_end_); | |
162 } | |
163 } | 162 } |
164 | 163 |
165 void RenderWidgetHostViewViews::WasHidden() { | 164 void RenderWidgetHostViewViews::WasHidden() { |
166 if (is_hidden_) | 165 if (is_hidden_) |
167 return; | 166 return; |
168 | 167 |
169 // If we receive any more paint messages while we are hidden, we want to | 168 // If we receive any more paint messages while we are hidden, we want to |
170 // ignore them so we don't re-allocate the backing store. We will paint | 169 // ignore them so we don't re-allocate the backing store. We will paint |
171 // everything again when we become selected again. | 170 // everything again when we become selected again. |
172 is_hidden_ = true; | 171 is_hidden_ = true; |
173 | 172 |
174 // If we have a renderer, then inform it that we are being hidden so it can | 173 // If we have a renderer, then inform it that we are being hidden so it can |
175 // reduce its resource utilization. | 174 // reduce its resource utilization. |
176 if (host_) | 175 if (host_) |
177 host_->WasHidden(); | 176 host_->WasHidden(); |
178 | 177 |
| 178 if (!update_touch_selection_.empty()) |
| 179 update_touch_selection_.RevokeAll(); |
| 180 |
179 if (touch_selection_controller_.get()) | 181 if (touch_selection_controller_.get()) |
180 touch_selection_controller_->ClientViewLostFocus(); | 182 touch_selection_controller_->ClientViewLostFocus(); |
181 } | 183 } |
182 | 184 |
183 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { | 185 void RenderWidgetHostViewViews::SetSize(const gfx::Size& size) { |
184 // This is called when webkit has sent us a Move message. | 186 // This is called when webkit has sent us a Move message. |
185 int width = std::min(size.width(), kMaxWindowWidth); | 187 int width = std::min(size.width(), kMaxWindowWidth); |
186 int height = std::min(size.height(), kMaxWindowHeight); | 188 int height = std::min(size.height(), kMaxWindowHeight); |
187 if (requested_size_.width() != width || | 189 if (requested_size_.width() != width || |
188 requested_size_.height() != height) { | 190 requested_size_.height() != height) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 341 } |
340 | 342 |
341 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, | 343 void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, |
342 const ui::Range& range, | 344 const ui::Range& range, |
343 const gfx::Point& start, | 345 const gfx::Point& start, |
344 const gfx::Point& end) { | 346 const gfx::Point& end) { |
345 // TODO(anicolao): deal with the clipboard without GTK | 347 // TODO(anicolao): deal with the clipboard without GTK |
346 NOTIMPLEMENTED(); | 348 NOTIMPLEMENTED(); |
347 selection_start_ = start; | 349 selection_start_ = start; |
348 selection_end_ = end; | 350 selection_end_ = end; |
349 if (touch_selection_controller_.get()) | 351 |
350 touch_selection_controller_->SelectionChanged(start, end); | 352 // TODO(sad): This is a workaround for a webkit bug: |
| 353 // https://bugs.webkit.org/show_bug.cgi?id=67464 |
| 354 // Remove this when the bug gets fixed. |
| 355 // |
| 356 // Webkit can send spurious selection-change on text-input (e.g. when |
| 357 // inserting text at the beginning of a non-empty text control). But in those |
| 358 // cases, it does send the correct selection information quickly afterwards. |
| 359 // So delay the notification to the touch-selection controller. |
| 360 if (update_touch_selection_.empty()) { |
| 361 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 362 update_touch_selection_.NewRunnableMethod( |
| 363 &RenderWidgetHostViewViews::UpdateTouchSelectionController), |
| 364 kTouchControllerUpdateDelay); |
| 365 } |
351 } | 366 } |
352 | 367 |
353 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { | 368 void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { |
354 is_showing_context_menu_ = showing; | 369 is_showing_context_menu_ = showing; |
355 } | 370 } |
356 | 371 |
357 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 372 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
358 const gfx::Size& size) { | 373 const gfx::Size& size) { |
359 return new BackingStoreSkia(host_, size); | 374 return new BackingStoreSkia(host_, size); |
360 } | 375 } |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 824 |
810 void RenderWidgetHostViewViews::FinishImeCompositionSession() { | 825 void RenderWidgetHostViewViews::FinishImeCompositionSession() { |
811 if (!has_composition_text_) | 826 if (!has_composition_text_) |
812 return; | 827 return; |
813 if (host_) | 828 if (host_) |
814 host_->ImeConfirmComposition(); | 829 host_->ImeConfirmComposition(); |
815 DCHECK(GetInputMethod()); | 830 DCHECK(GetInputMethod()); |
816 GetInputMethod()->CancelComposition(this); | 831 GetInputMethod()->CancelComposition(this); |
817 has_composition_text_ = false; | 832 has_composition_text_ = false; |
818 } | 833 } |
| 834 |
| 835 void RenderWidgetHostViewViews::UpdateTouchSelectionController() { |
| 836 if (touch_selection_controller_.get()) |
| 837 touch_selection_controller_->SelectionChanged(selection_start_, |
| 838 selection_end_); |
| 839 } |
OLD | NEW |