Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: content/renderer/render_view_impl.cc

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/renderer/render_view_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/render_view_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 navigation_gesture_(NavigationGestureUnknown), 784 navigation_gesture_(NavigationGestureUnknown),
785 opened_by_user_gesture_(true), 785 opened_by_user_gesture_(true),
786 opener_suppressed_(false), 786 opener_suppressed_(false),
787 page_id_(-1), 787 page_id_(-1),
788 last_page_id_sent_to_browser_(-1), 788 last_page_id_sent_to_browser_(-1),
789 next_page_id_(params->next_page_id), 789 next_page_id_(params->next_page_id),
790 history_list_offset_(-1), 790 history_list_offset_(-1),
791 history_list_length_(0), 791 history_list_length_(0),
792 target_url_status_(TARGET_NONE), 792 target_url_status_(TARGET_NONE),
793 selection_text_offset_(0), 793 selection_text_offset_(0),
794 selection_range_(ui::Range::InvalidRange()), 794 selection_range_(gfx::Range::InvalidRange()),
795 #if defined(OS_ANDROID) 795 #if defined(OS_ANDROID)
796 top_controls_constraints_(cc::BOTH), 796 top_controls_constraints_(cc::BOTH),
797 #endif 797 #endif
798 cached_is_main_frame_pinned_to_left_(false), 798 cached_is_main_frame_pinned_to_left_(false),
799 cached_is_main_frame_pinned_to_right_(false), 799 cached_is_main_frame_pinned_to_right_(false),
800 cached_has_main_frame_horizontal_scrollbar_(false), 800 cached_has_main_frame_horizontal_scrollbar_(false),
801 cached_has_main_frame_vertical_scrollbar_(false), 801 cached_has_main_frame_vertical_scrollbar_(false),
802 cookie_jar_(this), 802 cookie_jar_(this),
803 notification_provider_(NULL), 803 notification_provider_(NULL),
804 geolocation_dispatcher_(NULL), 804 geolocation_dispatcher_(NULL),
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 void RenderViewImpl::SimulateImeSetComposition( 1266 void RenderViewImpl::SimulateImeSetComposition(
1267 const string16& text, 1267 const string16& text,
1268 const std::vector<WebKit::WebCompositionUnderline>& underlines, 1268 const std::vector<WebKit::WebCompositionUnderline>& underlines,
1269 int selection_start, 1269 int selection_start,
1270 int selection_end) { 1270 int selection_end) {
1271 OnImeSetComposition(text, underlines, selection_start, selection_end); 1271 OnImeSetComposition(text, underlines, selection_start, selection_end);
1272 } 1272 }
1273 1273
1274 void RenderViewImpl::SimulateImeConfirmComposition( 1274 void RenderViewImpl::SimulateImeConfirmComposition(
1275 const string16& text, 1275 const string16& text,
1276 const ui::Range& replacement_range) { 1276 const gfx::Range& replacement_range) {
1277 OnImeConfirmComposition(text, replacement_range, false); 1277 OnImeConfirmComposition(text, replacement_range, false);
1278 } 1278 }
1279 1279
1280 #if defined(OS_WIN) 1280 #if defined(OS_WIN)
1281 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) { 1281 void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
1282 if (focused) 1282 if (focused)
1283 focused_plugin_id_ = plugin_id; 1283 focused_plugin_id_ = plugin_id;
1284 else 1284 else
1285 focused_plugin_id_ = -1; 1285 focused_plugin_id_ = -1;
1286 } 1286 }
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 // selection. If that's the case, update the render view's state just prior 2660 // selection. If that's the case, update the render view's state just prior
2661 // to showing the context menu. 2661 // to showing the context menu.
2662 // TODO(asvitkine): http://crbug.com/152432 2662 // TODO(asvitkine): http://crbug.com/152432
2663 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_, 2663 if (ShouldUpdateSelectionTextFromContextMenuParams(selection_text_,
2664 selection_text_offset_, 2664 selection_text_offset_,
2665 selection_range_, 2665 selection_range_,
2666 params)) { 2666 params)) {
2667 selection_text_ = params.selection_text; 2667 selection_text_ = params.selection_text;
2668 // TODO(asvitkine): Text offset and range is not available in this case. 2668 // TODO(asvitkine): Text offset and range is not available in this case.
2669 selection_text_offset_ = 0; 2669 selection_text_offset_ = 0;
2670 selection_range_ = ui::Range(0, selection_text_.length()); 2670 selection_range_ = gfx::Range(0, selection_text_.length());
2671 Send(new ViewHostMsg_SelectionChanged(routing_id_, 2671 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2672 selection_text_, 2672 selection_text_,
2673 selection_text_offset_, 2673 selection_text_offset_,
2674 selection_range_)); 2674 selection_range_));
2675 } 2675 }
2676 2676
2677 // frame is NULL if invoked by BlockedPlugin. 2677 // frame is NULL if invoked by BlockedPlugin.
2678 if (frame) 2678 if (frame)
2679 params.frame_id = frame->identifier(); 2679 params.frame_id = frame->identifier();
2680 2680
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after
4163 match_count, 4163 match_count,
4164 selection_rect, 4164 selection_rect,
4165 ordinal, 4165 ordinal,
4166 final_status_update)); 4166 final_status_update));
4167 } 4167 }
4168 4168
4169 // static 4169 // static
4170 bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams( 4170 bool RenderViewImpl::ShouldUpdateSelectionTextFromContextMenuParams(
4171 const string16& selection_text, 4171 const string16& selection_text,
4172 size_t selection_text_offset, 4172 size_t selection_text_offset,
4173 const ui::Range& selection_range, 4173 const gfx::Range& selection_range,
4174 const ContextMenuParams& params) { 4174 const ContextMenuParams& params) {
4175 string16 trimmed_selection_text; 4175 string16 trimmed_selection_text;
4176 if (!selection_text.empty() && !selection_range.is_empty()) { 4176 if (!selection_text.empty() && !selection_range.is_empty()) {
4177 const int start = selection_range.GetMin() - selection_text_offset; 4177 const int start = selection_range.GetMin() - selection_text_offset;
4178 const size_t length = selection_range.length(); 4178 const size_t length = selection_range.length();
4179 if (start >= 0 && start + length <= selection_text.length()) { 4179 if (start >= 0 && start + length <= selection_text.length()) {
4180 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL, 4180 TrimWhitespace(selection_text.substr(start, length), TRIM_ALL,
4181 &trimmed_selection_text); 4181 &trimmed_selection_text);
4182 } 4182 }
4183 } 4183 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4487 SendUpdateState(item); 4487 SendUpdateState(item);
4488 } 4488 }
4489 4489
4490 void RenderViewImpl::SyncSelectionIfRequired() { 4490 void RenderViewImpl::SyncSelectionIfRequired() {
4491 WebFrame* frame = webview()->focusedFrame(); 4491 WebFrame* frame = webview()->focusedFrame();
4492 if (!frame) 4492 if (!frame)
4493 return; 4493 return;
4494 4494
4495 string16 text; 4495 string16 text;
4496 size_t offset; 4496 size_t offset;
4497 ui::Range range; 4497 gfx::Range range;
4498 #if defined(ENABLE_PLUGINS) 4498 #if defined(ENABLE_PLUGINS)
4499 if (focused_pepper_plugin_) { 4499 if (focused_pepper_plugin_) {
4500 focused_pepper_plugin_->GetSurroundingText(&text, &range); 4500 focused_pepper_plugin_->GetSurroundingText(&text, &range);
4501 offset = 0; // Pepper API does not support offset reporting. 4501 offset = 0; // Pepper API does not support offset reporting.
4502 // TODO(kinaba): cut as needed. 4502 // TODO(kinaba): cut as needed.
4503 } else 4503 } else
4504 #endif 4504 #endif
4505 { 4505 {
4506 size_t location, length; 4506 size_t location, length;
4507 if (!webview()->caretOrSelectionRange(&location, &length)) 4507 if (!webview()->caretOrSelectionRange(&location, &length))
4508 return; 4508 return;
4509 4509
4510 range = ui::Range(location, location + length); 4510 range = gfx::Range(location, location + length);
4511 4511
4512 if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) { 4512 if (webview()->textInputInfo().type != WebKit::WebTextInputTypeNone) {
4513 // If current focused element is editable, we will send 100 more chars 4513 // If current focused element is editable, we will send 100 more chars
4514 // before and after selection. It is for input method surrounding text 4514 // before and after selection. It is for input method surrounding text
4515 // feature. 4515 // feature.
4516 if (location > kExtraCharsBeforeAndAfterSelection) 4516 if (location > kExtraCharsBeforeAndAfterSelection)
4517 offset = location - kExtraCharsBeforeAndAfterSelection; 4517 offset = location - kExtraCharsBeforeAndAfterSelection;
4518 else 4518 else
4519 offset = 0; 4519 offset = 0;
4520 length = location + length - offset + kExtraCharsBeforeAndAfterSelection; 4520 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
5878 return; 5878 return;
5879 } 5879 }
5880 #endif // OS_WIN 5880 #endif // OS_WIN
5881 #endif // ENABLE_PLUGINS 5881 #endif // ENABLE_PLUGINS
5882 RenderWidget::OnImeSetComposition(text, 5882 RenderWidget::OnImeSetComposition(text,
5883 underlines, 5883 underlines,
5884 selection_start, 5884 selection_start,
5885 selection_end); 5885 selection_end);
5886 } 5886 }
5887 5887
5888 void RenderViewImpl::OnImeConfirmComposition(const string16& text, 5888 void RenderViewImpl::OnImeConfirmComposition(
5889 const ui::Range& replacement_range, 5889 const string16& text,
5890 bool keep_selection) { 5890 const gfx::Range& replacement_range,
5891 bool keep_selection) {
5891 #if defined(ENABLE_PLUGINS) 5892 #if defined(ENABLE_PLUGINS)
5892 if (focused_pepper_plugin_) { 5893 if (focused_pepper_plugin_) {
5893 // When a PPAPI plugin has focus, we bypass WebKit. 5894 // When a PPAPI plugin has focus, we bypass WebKit.
5894 // Here, text.empty() has a special meaning. It means to commit the last 5895 // Here, text.empty() has a special meaning. It means to commit the last
5895 // update of composition text (see 5896 // update of composition text (see
5896 // RenderWidgetHost::ImeConfirmComposition()). 5897 // RenderWidgetHost::ImeConfirmComposition()).
5897 const string16& last_text = text.empty() ? pepper_composition_text_ : text; 5898 const string16& last_text = text.empty() ? pepper_composition_text_ : text;
5898 5899
5899 // last_text is empty only when both text and pepper_composition_text_ is. 5900 // last_text is empty only when both text and pepper_composition_text_ is.
5900 // Ignore it. 5901 // Ignore it.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
6035 for (size_t i = 0; i < character_count; ++i) { 6036 for (size_t i = 0; i < character_count; ++i) {
6036 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) { 6037 if (!frame->firstRectForCharacterRange(start_offset + i, 1, webrect)) {
6037 DLOG(ERROR) << "Could not retrieve character rectangle at " << i; 6038 DLOG(ERROR) << "Could not retrieve character rectangle at " << i;
6038 bounds->clear(); 6039 bounds->clear();
6039 return; 6040 return;
6040 } 6041 }
6041 bounds->push_back(webrect); 6042 bounds->push_back(webrect);
6042 } 6043 }
6043 } 6044 }
6044 6045
6045 void RenderViewImpl::GetCompositionRange(ui::Range* range) { 6046 void RenderViewImpl::GetCompositionRange(gfx::Range* range) {
6046 #if defined(ENABLE_PLUGINS) 6047 #if defined(ENABLE_PLUGINS)
6047 if (focused_pepper_plugin_) { 6048 if (focused_pepper_plugin_) {
6048 return; 6049 return;
6049 } 6050 }
6050 #endif 6051 #endif
6051 RenderWidget::GetCompositionRange(range); 6052 RenderWidget::GetCompositionRange(range);
6052 } 6053 }
6053 #endif 6054 #endif
6054 6055
6055 bool RenderViewImpl::CanComposeInline() { 6056 bool RenderViewImpl::CanComposeInline() {
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
6517 for (size_t i = 0; i < icon_urls.size(); i++) { 6518 for (size_t i = 0; i < icon_urls.size(); i++) {
6518 WebURL url = icon_urls[i].iconURL(); 6519 WebURL url = icon_urls[i].iconURL();
6519 if (!url.isEmpty()) 6520 if (!url.isEmpty())
6520 urls.push_back(FaviconURL(url, 6521 urls.push_back(FaviconURL(url,
6521 ToFaviconType(icon_urls[i].iconType()))); 6522 ToFaviconType(icon_urls[i].iconType())));
6522 } 6523 }
6523 SendUpdateFaviconURL(urls); 6524 SendUpdateFaviconURL(urls);
6524 } 6525 }
6525 6526
6526 } // namespace content 6527 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_view_impl.h ('k') | content/renderer/render_view_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698