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

Side by Side Diff: sky/engine/web/WebViewImpl.cpp

Issue 770223002: Remove lots of code from the WebWidget/WebView/WebFrame layer. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 m_spellCheckClient = spellCheckClient; 131 m_spellCheckClient = spellCheckClient;
132 } 132 }
133 133
134 WebViewImpl::WebViewImpl(WebViewClient* client) 134 WebViewImpl::WebViewImpl(WebViewClient* client)
135 : m_client(client) 135 : m_client(client)
136 , m_spellCheckClient(0) 136 , m_spellCheckClient(0)
137 , m_chromeClientImpl(this) 137 , m_chromeClientImpl(this)
138 , m_editorClientImpl(this) 138 , m_editorClientImpl(this)
139 , m_spellCheckerClientImpl(this) 139 , m_spellCheckerClientImpl(this)
140 , m_fixedLayoutSizeLock(false) 140 , m_fixedLayoutSizeLock(false)
141 , m_doingDragAndDrop(false)
142 , m_ignoreInputEvents(false) 141 , m_ignoreInputEvents(false)
143 , m_compositorDeviceScaleFactorOverride(0) 142 , m_compositorDeviceScaleFactorOverride(0)
144 , m_rootLayerScale(1) 143 , m_rootLayerScale(1)
145 , m_suppressNextKeypressEvent(false) 144 , m_suppressNextKeypressEvent(false)
146 , m_imeAcceptEvents(true) 145 , m_imeAcceptEvents(true)
147 , m_isTransparent(false) 146 , m_isTransparent(false)
148 , m_tabsToLinks(false) 147 , m_tabsToLinks(false)
149 , m_rootLayer(0) 148 , m_rootLayer(0)
150 , m_matchesHeuristicsForGpuRasterization(false) 149 , m_matchesHeuristicsForGpuRasterization(false)
151 , m_recreatingGraphicsContext(false) 150 , m_recreatingGraphicsContext(false)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 195 }
197 196
198 void WebViewImpl::handleMouseLeave(LocalFrame& mainFrame, const WebMouseEvent& e vent) 197 void WebViewImpl::handleMouseLeave(LocalFrame& mainFrame, const WebMouseEvent& e vent)
199 { 198 {
200 m_client->setMouseOverURL(WebURL()); 199 m_client->setMouseOverURL(WebURL());
201 PageWidgetEventHandler::handleMouseLeave(mainFrame, event); 200 PageWidgetEventHandler::handleMouseLeave(mainFrame, event);
202 } 201 }
203 202
204 void WebViewImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& ev ent) 203 void WebViewImpl::handleMouseDown(LocalFrame& mainFrame, const WebMouseEvent& ev ent)
205 { 204 {
206 m_lastMouseDownPoint = WebPoint(event.x, event.y);
207
208 PageWidgetEventHandler::handleMouseDown(mainFrame, event); 205 PageWidgetEventHandler::handleMouseDown(mainFrame, event);
209 206
210 if (event.button == WebMouseEvent::ButtonLeft && m_mouseCaptureNode) 207 if (event.button == WebMouseEvent::ButtonLeft && m_mouseCaptureNode)
211 m_mouseCaptureGestureToken = mainFrame.eventHandler().takeLastMouseDownG estureToken(); 208 m_mouseCaptureGestureToken = mainFrame.eventHandler().takeLastMouseDownG estureToken();
212 } 209 }
213 210
214 void WebViewImpl::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& even t) 211 void WebViewImpl::handleMouseUp(LocalFrame& mainFrame, const WebMouseEvent& even t)
215 { 212 {
216 PageWidgetEventHandler::handleMouseUp(mainFrame, event); 213 PageWidgetEventHandler::handleMouseUp(mainFrame, event);
217 } 214 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 { 390 {
394 m_continuousPaintingEnabled = enabled; 391 m_continuousPaintingEnabled = enabled;
395 m_client->scheduleAnimation(); 392 m_client->scheduleAnimation();
396 } 393 }
397 394
398 void WebViewImpl::setShowScrollBottleneckRects(bool show) 395 void WebViewImpl::setShowScrollBottleneckRects(bool show)
399 { 396 {
400 m_showScrollBottleneckRects = show; 397 m_showScrollBottleneckRects = show;
401 } 398 }
402 399
403 void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const
404 {
405 const LocalFrame* frame = focusedCoreFrame();
406 if (!frame)
407 return;
408
409 Element* root = frame->selection().rootEditableElementOrDocumentElement();
410 if (!root)
411 return;
412
413 IntRect boundingBox = root->pixelSnappedBoundingBox();
414 boundingBox = root->document().frame()->view()->contentsToWindow(boundingBox );
415 bounds = boundingBox;
416 }
417
418 void WebViewImpl::acceptLanguagesChanged() 400 void WebViewImpl::acceptLanguagesChanged()
419 { 401 {
420 if (!page()) 402 if (!page())
421 return; 403 return;
422 404
423 page()->acceptLanguagesChanged(); 405 page()->acceptLanguagesChanged();
424 } 406 }
425 407
426 bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event) 408 bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event)
427 { 409 {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // events. 474 // events.
493 if (evt.isSystemKey()) 475 if (evt.isSystemKey())
494 return false; 476 return false;
495 477
496 if (!suppress && !handler.keyEvent(evt)) 478 if (!suppress && !handler.keyEvent(evt))
497 return keyEventDefault(event); 479 return keyEventDefault(event);
498 480
499 return true; 481 return true;
500 } 482 }
501 483
502 WebRect WebViewImpl::computeBlockBounds(const WebRect& rect, bool ignoreClipping )
503 {
504 if (!mainFrameImpl())
505 return WebRect();
506
507 // Use the rect-based hit test to find the node.
508 IntPoint point = mainFrameImpl()->frameView()->windowToContents(IntPoint(rec t.x, rect.y));
509 HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitT estRequest::Active | (ignoreClipping ? HitTestRequest::IgnoreClipping : 0);
510 HitTestResult result = mainFrameImpl()->frame()->eventHandler().hitTestResul tAtPoint(point, hitType, IntSize(rect.width, rect.height));
511
512 Node* node = result.innerNonSharedNode();
513 if (!node)
514 return WebRect();
515
516 // Find the block type node based on the hit node.
517 // FIXME: This wants to walk composed tree with NodeRenderingTraversal::pare nt().
518 while (node && (!node->renderer() || node->renderer()->isInline()))
519 node = NodeRenderingTraversal::parent(node);
520
521 // Return the bounding box in the window coordinate system.
522 if (node) {
523 IntRect rect = node->Node::pixelSnappedBoundingBox();
524 LocalFrame* frame = node->document().frame();
525 return frame->view()->contentsToWindow(rect);
526 }
527 return WebRect();
528 }
529
530 WebRect WebViewImpl::widenRectWithinPageBounds(const WebRect& source, int target Margin, int minimumMargin)
531 {
532 WebSize maxSize;
533 if (mainFrame())
534 maxSize = mainFrame()->contentsSize();
535 int leftMargin = targetMargin;
536 int rightMargin = targetMargin;
537
538 const int absoluteSourceX = source.x;
539 if (leftMargin > absoluteSourceX) {
540 leftMargin = absoluteSourceX;
541 rightMargin = std::max(leftMargin, minimumMargin);
542 }
543
544 const int maximumRightMargin = maxSize.width - (source.width + absoluteSourc eX);
545 if (rightMargin > maximumRightMargin) {
546 rightMargin = maximumRightMargin;
547 leftMargin = std::min(leftMargin, std::max(rightMargin, minimumMargin));
548 }
549
550 const int newWidth = source.width + leftMargin + rightMargin;
551 const int newX = source.x - leftMargin;
552
553 ASSERT(newWidth >= 0);
554 ASSERT(newX + newWidth <= maxSize.width);
555
556 return WebRect(newX, source.y, newWidth, source.height);
557 }
558
559 void WebViewImpl::computeScaleAndScrollForBlockRect(const WebPoint& hitPoint, co nst WebRect& blockRect, float padding, float defaultScaleWhenAlreadyLegible, flo at& scale, WebPoint& scroll)
560 {
561 //FIXME(sky)
562 }
563
564 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event) 484 bool WebViewImpl::keyEventDefault(const WebKeyboardEvent& event)
565 { 485 {
566 LocalFrame* frame = focusedCoreFrame(); 486 LocalFrame* frame = focusedCoreFrame();
567 if (!frame) 487 if (!frame)
568 return false; 488 return false;
569 489
570 switch (event.type) { 490 switch (event.type) {
571 case WebInputEvent::Char: 491 case WebInputEvent::Char:
572 if (event.windowsKeyCode == VKEY_SPACE) { 492 if (event.windowsKeyCode == VKEY_SPACE) {
573 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PR IOR : VKEY_NEXT); 493 int keyCode = ((event.modifiers & WebInputEvent::ShiftKey) ? VKEY_PR IOR : VKEY_NEXT);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 m_page.clear(); 597 m_page.clear();
678 } 598 }
679 599
680 // Reset the delegate to prevent notifications being sent as we're being 600 // Reset the delegate to prevent notifications being sent as we're being
681 // deleted. 601 // deleted.
682 m_client = 0; 602 m_client = 0;
683 603
684 deref(); // Balances ref() acquired in WebView::create 604 deref(); // Balances ref() acquired in WebView::create
685 } 605 }
686 606
687 void WebViewImpl::willStartLiveResize()
688 {
689 // FIXME(sky): Remove
690 }
691
692 WebSize WebViewImpl::size() 607 WebSize WebViewImpl::size()
693 { 608 {
694 return m_size; 609 return m_size;
695 } 610 }
696 611
697 WebLocalFrameImpl* WebViewImpl::localFrameRootTemporary() const 612 WebLocalFrameImpl* WebViewImpl::localFrameRootTemporary() const
698 { 613 {
699 // FIXME(sky): remove 614 // FIXME(sky): remove
700 return WebLocalFrameImpl::fromFrame(page()->mainFrame()); 615 return WebLocalFrameImpl::fromFrame(page()->mainFrame());
701 } 616 }
(...skipping 15 matching lines...) Expand all
717 632
718 FrameView* view = localFrameRootTemporary()->frameView(); 633 FrameView* view = localFrameRootTemporary()->frameView();
719 if (!view) 634 if (!view)
720 return; 635 return;
721 636
722 m_size = newSize; 637 m_size = newSize;
723 performResize(); 638 performResize();
724 sendResizeEventAndRepaint(); 639 sendResizeEventAndRepaint();
725 } 640 }
726 641
727 void WebViewImpl::willEndLiveResize()
728 {
729 // FIXME(sky): Remove
730 }
731
732 void WebViewImpl::beginFrame(const WebBeginFrameArgs& frameTime) 642 void WebViewImpl::beginFrame(const WebBeginFrameArgs& frameTime)
733 { 643 {
734 TRACE_EVENT0("blink", "WebViewImpl::beginFrame"); 644 TRACE_EVENT0("blink", "WebViewImpl::beginFrame");
735 645
736 WebBeginFrameArgs validFrameTime(frameTime); 646 WebBeginFrameArgs validFrameTime(frameTime);
737 if (!validFrameTime.lastFrameTimeMonotonic) 647 if (!validFrameTime.lastFrameTimeMonotonic)
738 validFrameTime.lastFrameTimeMonotonic = monotonicallyIncreasingTime(); 648 validFrameTime.lastFrameTimeMonotonic = monotonicallyIncreasingTime();
739 649
740 // Create synthetic wheel events as necessary for fling. 650 // Create synthetic wheel events as necessary for fling.
741 if (m_gestureAnimation) { 651 if (m_gestureAnimation) {
(...skipping 14 matching lines...) Expand all
756 WTF_LOG(ScriptedAnimationController, "WebViewImpl::beginFrame: page = %d", ! m_page ? 0 : 1); 666 WTF_LOG(ScriptedAnimationController, "WebViewImpl::beginFrame: page = %d", ! m_page ? 0 : 1);
757 if (!m_page) 667 if (!m_page)
758 return; 668 return;
759 669
760 PageWidgetDelegate::animate(m_page.get(), validFrameTime.lastFrameTimeMonoto nic); 670 PageWidgetDelegate::animate(m_page.get(), validFrameTime.lastFrameTimeMonoto nic);
761 671
762 if (m_continuousPaintingEnabled) 672 if (m_continuousPaintingEnabled)
763 m_client->scheduleAnimation(); 673 m_client->scheduleAnimation();
764 } 674 }
765 675
766 void WebViewImpl::didCommitFrameToCompositor()
767 {
768 }
769
770 void WebViewImpl::layout() 676 void WebViewImpl::layout()
771 { 677 {
772 TRACE_EVENT0("blink", "WebViewImpl::layout"); 678 TRACE_EVENT0("blink", "WebViewImpl::layout");
773 if (!localFrameRootTemporary()) 679 if (!localFrameRootTemporary())
774 return; 680 return;
775 PageWidgetDelegate::layout(m_page.get(), localFrameRootTemporary()->frame()) ; 681 PageWidgetDelegate::layout(m_page.get(), localFrameRootTemporary()->frame()) ;
776 } 682 }
777 683
778 void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect) 684 void WebViewImpl::paint(WebCanvas* canvas, const WebRect& rect)
779 { 685 {
780 double paintStart = currentTime(); 686 double paintStart = currentTime();
781 PageWidgetDelegate::paint(m_page.get(), canvas, rect, isTransparent() ? Page WidgetDelegate::Translucent : PageWidgetDelegate::Opaque); 687 PageWidgetDelegate::paint(m_page.get(), canvas, rect, isTransparent() ? Page WidgetDelegate::Translucent : PageWidgetDelegate::Opaque);
782 double paintEnd = currentTime(); 688 double paintEnd = currentTime();
783 double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStart); 689 double pixelsPerSec = (rect.width * rect.height) / (paintEnd - paintStart);
784 Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintDurationM S", (paintEnd - paintStart) * 1000, 0, 120, 30); 690 Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintDurationM S", (paintEnd - paintStart) * 1000, 0, 120, 30);
785 Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintMegapixPe rSecond", pixelsPerSec / 1000000, 10, 210, 30); 691 Platform::current()->histogramCustomCounts("Renderer4.SoftwarePaintMegapixPe rSecond", pixelsPerSec / 1000000, 10, 210, 30);
786 } 692 }
787 693
788 bool WebViewImpl::isTrackingRepaints() const 694 bool WebViewImpl::isTrackingRepaints() const
789 { 695 {
790 if (!page()) 696 if (!page())
791 return false; 697 return false;
792 FrameView* view = page()->mainFrame()->view(); 698 FrameView* view = page()->mainFrame()->view();
793 return view->isTrackingPaintInvalidations(); 699 return view->isTrackingPaintInvalidations();
794 } 700 }
795 701
796 void WebViewImpl::themeChanged()
797 {
798 if (!page())
799 return;
800 FrameView* view = page()->mainFrame()->view();
801
802 WebRect damagedRect(0, 0, m_size.width, m_size.height);
803 view->invalidateRect(damagedRect);
804 }
805
806 bool WebViewImpl::hasHorizontalScrollbar() 702 bool WebViewImpl::hasHorizontalScrollbar()
807 { 703 {
808 // FIXME(sky): Remove 704 // FIXME(sky): Remove
809 return false; 705 return false;
810 } 706 }
811 707
812 bool WebViewImpl::hasVerticalScrollbar() 708 bool WebViewImpl::hasVerticalScrollbar()
813 { 709 {
814 // FIXME(sky): Remove 710 // FIXME(sky): Remove
815 return false; 711 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 case WebInputEvent::TouchCancel: 757 case WebInputEvent::TouchCancel:
862 return EventTypeNames::touchcancel; 758 return EventTypeNames::touchcancel;
863 default: 759 default:
864 return String("unknown"); 760 return String("unknown");
865 } 761 }
866 } 762 }
867 763
868 bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent) 764 bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent)
869 { 765 {
870 TRACE_EVENT1("input", "WebViewImpl::handleInputEvent", "type", inputTypeToNa me(inputEvent.type).ascii().data()); 766 TRACE_EVENT1("input", "WebViewImpl::handleInputEvent", "type", inputTypeToNa me(inputEvent.type).ascii().data());
871 // If we've started a drag and drop operation, ignore input events until
872 // we're done.
873 if (m_doingDragAndDrop)
874 return true;
875 767
876 // Report the event to be NOT processed by WebKit, so that the browser can h andle it appropriately. 768 // Report the event to be NOT processed by WebKit, so that the browser can h andle it appropriately.
877 if (m_ignoreInputEvents) 769 if (m_ignoreInputEvents)
878 return false; 770 return false;
879 771
880 TemporaryChange<const WebInputEvent*> currentEventChange(m_currentInputEvent , &inputEvent); 772 TemporaryChange<const WebInputEvent*> currentEventChange(m_currentInputEvent , &inputEvent);
881 773
882 if (m_mouseCaptureNode && WebInputEvent::isMouseEventType(inputEvent.type)) { 774 if (m_mouseCaptureNode && WebInputEvent::isMouseEventType(inputEvent.type)) {
883 TRACE_EVENT1("input", "captured mouse event", "type", inputEvent.type); 775 TRACE_EVENT1("input", "captured mouse event", "type", inputEvent.type);
884 // Save m_mouseCaptureNode since mouseCaptureLost() will clear it. 776 // Save m_mouseCaptureNode since mouseCaptureLost() will clear it.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 flags |= WebTextInputFlagSpellcheckOff; 1048 flags |= WebTextInputFlagSpellcheckOff;
1157 1049
1158 return flags; 1050 return flags;
1159 } 1051 }
1160 1052
1161 WebString WebViewImpl::inputModeOfFocusedElement() 1053 WebString WebViewImpl::inputModeOfFocusedElement()
1162 { 1054 {
1163 return WebString(); 1055 return WebString();
1164 } 1056 }
1165 1057
1166 bool WebViewImpl::selectionBounds(WebRect& anchor, WebRect& focus) const
1167 {
1168 const LocalFrame* localFrame = focusedCoreFrame();
1169 if (!localFrame)
1170 return false;
1171
1172 FrameSelection& selection = localFrame->selection();
1173
1174 if (selection.isCaret()) {
1175 anchor = focus = selection.absoluteCaretBounds();
1176 } else {
1177 RefPtr<Range> selectedRange = selection.toNormalizedRange();
1178 if (!selectedRange)
1179 return false;
1180
1181 RefPtr<Range> range(Range::create(selectedRange->startContainer()->docum ent(),
1182 selectedRange->startContainer(),
1183 selectedRange->startOffset(),
1184 selectedRange->startContainer(),
1185 selectedRange->startOffset()));
1186 anchor = localFrame->editor().firstRectForRange(range.get());
1187
1188 range = Range::create(selectedRange->endContainer()->document(),
1189 selectedRange->endContainer(),
1190 selectedRange->endOffset(),
1191 selectedRange->endContainer(),
1192 selectedRange->endOffset());
1193 focus = localFrame->editor().firstRectForRange(range.get());
1194 }
1195
1196 IntRect scaledAnchor(localFrame->view()->contentsToWindow(anchor));
1197 IntRect scaledFocus(localFrame->view()->contentsToWindow(focus));
1198
1199 anchor = scaledAnchor;
1200 focus = scaledFocus;
1201
1202 if (!selection.selection().isBaseFirst())
1203 std::swap(anchor, focus);
1204 return true;
1205 }
1206
1207 InputMethodContext* WebViewImpl::inputMethodContext() 1058 InputMethodContext* WebViewImpl::inputMethodContext()
1208 { 1059 {
1209 if (!m_imeAcceptEvents) 1060 if (!m_imeAcceptEvents)
1210 return 0; 1061 return 0;
1211 1062
1212 LocalFrame* focusedFrame = focusedCoreFrame(); 1063 LocalFrame* focusedFrame = focusedCoreFrame();
1213 if (!focusedFrame) 1064 if (!focusedFrame)
1214 return 0; 1065 return 0;
1215 1066
1216 Element* target = focusedFrame->document()->focusedElement(); 1067 Element* target = focusedFrame->document()->focusedElement();
(...skipping 14 matching lines...) Expand all
1231 if (InputMethodContext* context = inputMethodContext()) 1082 if (InputMethodContext* context = inputMethodContext())
1232 context->dispatchCandidateWindowUpdateEvent(); 1083 context->dispatchCandidateWindowUpdateEvent();
1233 } 1084 }
1234 1085
1235 void WebViewImpl::didHideCandidateWindow() 1086 void WebViewImpl::didHideCandidateWindow()
1236 { 1087 {
1237 if (InputMethodContext* context = inputMethodContext()) 1088 if (InputMethodContext* context = inputMethodContext())
1238 context->dispatchCandidateWindowHideEvent(); 1089 context->dispatchCandidateWindowHideEvent();
1239 } 1090 }
1240 1091
1241 bool WebViewImpl::selectionTextDirection(WebTextDirection& start, WebTextDirecti on& end) const
1242 {
1243 const LocalFrame* frame = focusedCoreFrame();
1244 if (!frame)
1245 return false;
1246 FrameSelection& selection = frame->selection();
1247 if (!selection.toNormalizedRange())
1248 return false;
1249 start = toWebTextDirection(selection.start().primaryDirection());
1250 end = toWebTextDirection(selection.end().primaryDirection());
1251 return true;
1252 }
1253
1254 bool WebViewImpl::isSelectionAnchorFirst() const
1255 {
1256 if (const LocalFrame* frame = focusedCoreFrame())
1257 return frame->selection().selection().isBaseFirst();
1258 return false;
1259 }
1260
1261 WebVector<WebCompositionUnderline> WebViewImpl::compositionUnderlines() const 1092 WebVector<WebCompositionUnderline> WebViewImpl::compositionUnderlines() const
1262 { 1093 {
1263 const LocalFrame* focused = focusedCoreFrame(); 1094 const LocalFrame* focused = focusedCoreFrame();
1264 if (!focused) 1095 if (!focused)
1265 return WebVector<WebCompositionUnderline>(); 1096 return WebVector<WebCompositionUnderline>();
1266 const Vector<CompositionUnderline>& underlines = focused->inputMethodControl ler().customCompositionUnderlines(); 1097 const Vector<CompositionUnderline>& underlines = focused->inputMethodControl ler().customCompositionUnderlines();
1267 WebVector<WebCompositionUnderline> results(underlines.size()); 1098 WebVector<WebCompositionUnderline> results(underlines.size());
1268 for (size_t index = 0; index < underlines.size(); ++index) { 1099 for (size_t index = 0; index < underlines.size(); ++index) {
1269 CompositionUnderline underline = underlines[index]; 1100 CompositionUnderline underline = underlines[index];
1270 results[index] = WebCompositionUnderline(underline.startOffset, underlin e.endOffset, static_cast<WebColor>(underline.color.rgb()), underline.thick, stat ic_cast<WebColor>(underline.backgroundColor.rgb())); 1101 results[index] = WebCompositionUnderline(underline.startOffset, underlin e.endOffset, static_cast<WebColor>(underline.color.rgb()), underline.thick, stat ic_cast<WebColor>(underline.backgroundColor.rgb()));
1271 } 1102 }
1272 return results; 1103 return results;
1273 } 1104 }
1274 1105
1275 WebColor WebViewImpl::backgroundColor() const 1106 WebColor WebViewImpl::backgroundColor() const
1276 { 1107 {
1277 if (isTransparent()) 1108 if (isTransparent())
1278 return Color::transparent; 1109 return Color::transparent;
1279 if (!m_page) 1110 if (!m_page)
1280 return m_baseBackgroundColor; 1111 return m_baseBackgroundColor;
1281 if (!m_page->mainFrame()) 1112 if (!m_page->mainFrame())
1282 return m_baseBackgroundColor; 1113 return m_baseBackgroundColor;
1283 FrameView* view = m_page->mainFrame()->view(); 1114 FrameView* view = m_page->mainFrame()->view();
1284 return view->documentBackgroundColor().rgb(); 1115 return view->documentBackgroundColor().rgb();
1285 } 1116 }
1286 1117
1287 bool WebViewImpl::caretOrSelectionRange(size_t* location, size_t* length)
1288 {
1289 const LocalFrame* focused = focusedCoreFrame();
1290 if (!focused)
1291 return false;
1292
1293 PlainTextRange selectionOffsets = focused->inputMethodController().getSelect ionOffsets();
1294 if (selectionOffsets.isNull())
1295 return false;
1296
1297 *location = selectionOffsets.start();
1298 *length = selectionOffsets.length();
1299 return true;
1300 }
1301
1302 void WebViewImpl::setTextDirection(WebTextDirection direction)
1303 {
1304 // The Editor::setBaseWritingDirection() function checks if we can change
1305 // the text direction of the selected node and updates its DOM "dir"
1306 // attribute and its CSS "direction" property.
1307 // So, we just call the function as Safari does.
1308 const LocalFrame* focused = focusedCoreFrame();
1309 if (!focused)
1310 return;
1311
1312 Editor& editor = focused->editor();
1313 if (!editor.canEdit())
1314 return;
1315
1316 switch (direction) {
1317 case WebTextDirectionDefault:
1318 editor.setBaseWritingDirection(NaturalWritingDirection);
1319 break;
1320
1321 case WebTextDirectionLeftToRight:
1322 editor.setBaseWritingDirection(LeftToRightWritingDirection);
1323 break;
1324
1325 case WebTextDirectionRightToLeft:
1326 editor.setBaseWritingDirection(RightToLeftWritingDirection);
1327 break;
1328
1329 default:
1330 notImplemented();
1331 break;
1332 }
1333 }
1334
1335 // WebView -------------------------------------------------------------------- 1118 // WebView --------------------------------------------------------------------
1336 1119
1337 WebSettingsImpl* WebViewImpl::settingsImpl() 1120 WebSettingsImpl* WebViewImpl::settingsImpl()
1338 { 1121 {
1339 if (!m_webSettings) 1122 if (!m_webSettings)
1340 m_webSettings = adoptPtr(new WebSettingsImpl(&m_page->settings())); 1123 m_webSettings = adoptPtr(new WebSettingsImpl(&m_page->settings()));
1341 ASSERT(m_webSettings); 1124 ASSERT(m_webSettings);
1342 return m_webSettings.get(); 1125 return m_webSettings.get();
1343 } 1126 }
1344 1127
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 return; 1206 return;
1424 1207
1425 // If a text field has focus, we need to make sure the selection controller 1208 // If a text field has focus, we need to make sure the selection controller
1426 // knows to remove selection from it. Otherwise, the text field is still 1209 // knows to remove selection from it. Otherwise, the text field is still
1427 // processing keyboard events even though focus has been moved to the page a nd 1210 // processing keyboard events even though focus has been moved to the page a nd
1428 // keystrokes get eaten as a result. 1211 // keystrokes get eaten as a result.
1429 if (oldFocusedElement->isContentEditable()) 1212 if (oldFocusedElement->isContentEditable())
1430 localFrame->selection().clear(); 1213 localFrame->selection().clear();
1431 } 1214 }
1432 1215
1433 void WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rect)
1434 {
1435 LocalFrame* frame = page()->mainFrame();
1436 Element* element = focusedElement();
1437 if (!frame || !frame->view() || !element)
1438 return;
1439
1440 float scale;
1441 IntPoint scroll;
1442 bool needAnimation;
1443 computeScaleAndScrollForFocusedNode(element, scale, scroll, needAnimation);
1444 }
1445
1446 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, float& newScale, IntPoint& newScroll, bool& needAnimation)
1447 {
1448 //FIXME(sky)
1449 }
1450
1451 void WebViewImpl::advanceFocus(bool reverse) 1216 void WebViewImpl::advanceFocus(bool reverse)
1452 { 1217 {
1453 page()->focusController().advanceFocus(reverse ? FocusTypeBackward : FocusTy peForward); 1218 page()->focusController().advanceFocus(reverse ? FocusTypeBackward : FocusTy peForward);
1454 } 1219 }
1455 1220
1456 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) 1221 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale)
1457 { 1222 {
1458 FrameView* view = mainFrameImpl()->frameView(); 1223 FrameView* view = mainFrameImpl()->frameView();
1459 if (!view) 1224 if (!view)
1460 return offset; 1225 return offset;
1461 1226
1462 return view->clampOffsetAtScale(offset, scale); 1227 return view->clampOffsetAtScale(offset, scale);
1463 } 1228 }
1464 1229
1465 void WebViewImpl::setMainFrameScrollOffset(const WebPoint& origin)
1466 {
1467 updateMainFrameScrollPosition(origin, false);
1468 }
1469
1470 float WebViewImpl::deviceScaleFactor() const 1230 float WebViewImpl::deviceScaleFactor() const
1471 { 1231 {
1472 if (!page()) 1232 if (!page())
1473 return 1; 1233 return 1;
1474 1234
1475 return page()->deviceScaleFactor(); 1235 return page()->deviceScaleFactor();
1476 } 1236 }
1477 1237
1478 void WebViewImpl::setDeviceScaleFactor(float scaleFactor) 1238 void WebViewImpl::setDeviceScaleFactor(float scaleFactor)
1479 { 1239 {
(...skipping 21 matching lines...) Expand all
1501 } 1261 }
1502 1262
1503 IntSize WebViewImpl::contentsSize() const 1263 IntSize WebViewImpl::contentsSize() const
1504 { 1264 {
1505 RenderView* root = page()->mainFrame()->contentRenderer(); 1265 RenderView* root = page()->mainFrame()->contentRenderer();
1506 if (!root) 1266 if (!root)
1507 return IntSize(); 1267 return IntSize();
1508 return root->documentRect().size(); 1268 return root->documentRect().size();
1509 } 1269 }
1510 1270
1511 WebSize WebViewImpl::contentsPreferredMinimumSize()
1512 {
1513 Document* document = m_page->mainFrame()->document();
1514 if (!document || !document->renderView() || !document->documentElement())
1515 return WebSize();
1516
1517 layout();
1518 FontCachePurgePreventer fontCachePurgePreventer; // Required by minPreferred LogicalWidth().
1519 return IntSize(document->renderView()->minPreferredLogicalWidth(), document- >documentElement()->scrollHeight());
1520 }
1521
1522 void WebViewImpl::resetScrollAndScaleState()
1523 {
1524 // FIXME(sky): Remove
1525 }
1526
1527 void WebViewImpl::setFixedLayoutSize(const WebSize& layoutSize)
1528 {
1529 if (!page())
1530 return;
1531
1532 LocalFrame* frame = page()->mainFrame();
1533 if (!frame)
1534 return;
1535
1536 RefPtr<FrameView> view = frame->view();
1537 if (!view)
1538 return;
1539
1540 m_fixedLayoutSizeLock = layoutSize.width || layoutSize.height;
1541
1542 if (m_fixedLayoutSizeLock)
1543 view->setLayoutSize(layoutSize);
1544 else
1545 updateMainFrameLayoutSize();
1546 }
1547
1548 WebHitTestResult WebViewImpl::hitTestResultAt(const WebPoint& point) 1271 WebHitTestResult WebViewImpl::hitTestResultAt(const WebPoint& point)
1549 { 1272 {
1550 return coreHitTestResultAt(point); 1273 return coreHitTestResultAt(point);
1551 } 1274 }
1552 1275
1553 HitTestResult WebViewImpl::coreHitTestResultAt(const WebPoint& point) 1276 HitTestResult WebViewImpl::coreHitTestResultAt(const WebPoint& point)
1554 { 1277 {
1555 IntPoint scaledPoint = point; 1278 IntPoint scaledPoint = point;
1556 return hitTestResultForWindowPos(scaledPoint); 1279 return hitTestResultForWindowPos(scaledPoint);
1557 } 1280 }
1558 1281
1559 void WebViewImpl::copyImageAt(const WebPoint& point)
1560 {
1561 if (!m_page)
1562 return;
1563
1564 HitTestResult result = hitTestResultForWindowPos(point);
1565
1566 if (result.absoluteImageURLIncludingCanvasDataURL().isEmpty()) {
1567 // There isn't actually an image at these coordinates. Might be because
1568 // the window scrolled while the context menu was open or because the pa ge
1569 // changed itself between when we thought there was an image here and wh en
1570 // we actually tried to retreive the image.
1571 //
1572 // FIXME: implement a cache of the most recent HitTestResult to avoid ha ving
1573 // to do two hit tests.
1574 return;
1575 }
1576
1577 m_page->mainFrame()->editor().copyImage(result);
1578 }
1579
1580 void WebViewImpl::saveImageAt(const WebPoint& point)
1581 {
1582 if (!m_page)
1583 return;
1584
1585 KURL url = hitTestResultForWindowPos(point).absoluteImageURLIncludingCanvasD ataURL();
1586
1587 if (url.isEmpty())
1588 return;
1589
1590 ResourceRequest request(url);
1591 request.setRequestContext(WebURLRequest::RequestContextDownload);
1592 m_page->mainFrame()->loaderClient()->loadURLExternally(
1593 request, NavigationPolicyDownloadTo, WebString());
1594 }
1595
1596 void WebViewImpl::dragSourceSystemDragEnded()
1597 {
1598 // FIXME(sky): Remove
1599 // It's possible for us to get this callback while not doing a drag if
1600 // it's from a previous page that got unloaded.
1601 if (m_doingDragAndDrop)
1602 m_doingDragAndDrop = false;
1603 }
1604
1605 void WebViewImpl::spellingMarkers(WebVector<uint32_t>* markers) 1282 void WebViewImpl::spellingMarkers(WebVector<uint32_t>* markers)
1606 { 1283 {
1607 Vector<uint32_t> result; 1284 Vector<uint32_t> result;
1608 LocalFrame* frame = m_page->mainFrame(); 1285 LocalFrame* frame = m_page->mainFrame();
1609 const DocumentMarkerVector& documentMarkers = frame->document()->markers().m arkers(); 1286 const DocumentMarkerVector& documentMarkers = frame->document()->markers().m arkers();
1610 for (size_t i = 0; i < documentMarkers.size(); ++i) 1287 for (size_t i = 0; i < documentMarkers.size(); ++i)
1611 result.append(documentMarkers[i]->hash()); 1288 result.append(documentMarkers[i]->hash());
1612 markers->assign(result); 1289 markers->assign(result);
1613 } 1290 }
1614 1291
(...skipping 18 matching lines...) Expand all
1633 1310
1634 WebRect damagedRect(0, 0, m_size.width, m_size.height); 1311 WebRect damagedRect(0, 0, m_size.width, m_size.height);
1635 m_client->didInvalidateRect(damagedRect); 1312 m_client->didInvalidateRect(damagedRect);
1636 } 1313 }
1637 1314
1638 void WebViewImpl::setCompositorDeviceScaleFactorOverride(float deviceScaleFactor ) 1315 void WebViewImpl::setCompositorDeviceScaleFactorOverride(float deviceScaleFactor )
1639 { 1316 {
1640 m_compositorDeviceScaleFactorOverride = deviceScaleFactor; 1317 m_compositorDeviceScaleFactorOverride = deviceScaleFactor;
1641 } 1318 }
1642 1319
1643 void WebViewImpl::setRootLayerTransform(const WebSize& rootLayerOffset, float ro otLayerScale)
1644 {
1645 if (m_rootLayerScale == rootLayerScale && m_rootLayerOffset == rootLayerOffs et)
1646 return;
1647 m_rootLayerScale = rootLayerScale;
1648 m_rootLayerOffset = rootLayerOffset;
1649 if (mainFrameImpl())
1650 mainFrameImpl()->setInputEventsTransformForEmulation(m_rootLayerOffset, m_rootLayerScale);
1651 updateRootLayerTransform();
1652 }
1653
1654 void WebViewImpl::extractSmartClipData(WebRect rect, WebString& clipText, WebStr ing& clipHtml, WebRect& clipRect)
1655 {
1656 }
1657
1658 void WebViewImpl::setIsTransparent(bool isTransparent) 1320 void WebViewImpl::setIsTransparent(bool isTransparent)
1659 { 1321 {
1660 // Set any existing frames to be transparent. 1322 // Set any existing frames to be transparent.
1661 m_page->mainFrame()->view()->setTransparent(isTransparent); 1323 m_page->mainFrame()->view()->setTransparent(isTransparent);
1662 1324
1663 // Future frames check this to know whether to be transparent. 1325 // Future frames check this to know whether to be transparent.
1664 m_isTransparent = isTransparent; 1326 m_isTransparent = isTransparent;
1665 } 1327 }
1666 1328
1667 bool WebViewImpl::isTransparent() const 1329 bool WebViewImpl::isTransparent() const
(...skipping 24 matching lines...) Expand all
1692 bool WebViewImpl::isActive() const 1354 bool WebViewImpl::isActive() const
1693 { 1355 {
1694 return page() ? page()->focusController().isActive() : false; 1356 return page() ? page()->focusController().isActive() : false;
1695 } 1357 }
1696 1358
1697 void WebViewImpl::setDomainRelaxationForbidden(bool forbidden, const WebString& scheme) 1359 void WebViewImpl::setDomainRelaxationForbidden(bool forbidden, const WebString& scheme)
1698 { 1360 {
1699 SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String(s cheme)); 1361 SchemeRegistry::setDomainRelaxationForbiddenForURLScheme(forbidden, String(s cheme));
1700 } 1362 }
1701 1363
1702 void WebViewImpl::setOpenedByDOM()
1703 {
1704 m_page->setOpenedByDOM();
1705 }
1706
1707 void WebViewImpl::setSelectionColors(unsigned activeBackgroundColor,
1708 unsigned activeForegroundColor,
1709 unsigned inactiveBackgroundColor,
1710 unsigned inactiveForegroundColor) {
1711 }
1712
1713 void WebViewImpl::didCommitLoad(bool isNewNavigation, bool isNavigationWithinPag e) 1364 void WebViewImpl::didCommitLoad(bool isNewNavigation, bool isNavigationWithinPag e)
1714 { 1365 {
1715 endActiveFlingAnimation(); 1366 endActiveFlingAnimation();
1716 m_userGestureObserved = false; 1367 m_userGestureObserved = false;
1717 if (!isNavigationWithinPage) 1368 if (!isNavigationWithinPage)
1718 UserGestureIndicator::clearProcessedUserGestureSinceLoad(); 1369 UserGestureIndicator::clearProcessedUserGestureSinceLoad();
1719 } 1370 }
1720 1371
1721 void WebViewImpl::layoutUpdated(WebLocalFrameImpl* webframe) 1372 void WebViewImpl::layoutUpdated(WebLocalFrameImpl* webframe)
1722 { 1373 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 void WebViewImpl::invalidateRect(const IntRect& rect) 1425 void WebViewImpl::invalidateRect(const IntRect& rect)
1775 { 1426 {
1776 m_client->didInvalidateRect(rect); 1427 m_client->didInvalidateRect(rect);
1777 } 1428 }
1778 1429
1779 void WebViewImpl::scheduleAnimation() 1430 void WebViewImpl::scheduleAnimation()
1780 { 1431 {
1781 m_client->scheduleAnimation(); 1432 m_client->scheduleAnimation();
1782 } 1433 }
1783 1434
1784 void WebViewImpl::updateMainFrameScrollPosition(const IntPoint& scrollPosition, bool programmaticScroll)
1785 {
1786 // FIXME(sky): Remove
1787 }
1788
1789 void WebViewImpl::updateRootLayerTransform()
1790 {
1791 // FIXME(sky): Remove
1792 }
1793
1794 bool WebViewImpl::detectContentOnTouch(const WebPoint& position) 1435 bool WebViewImpl::detectContentOnTouch(const WebPoint& position)
1795 { 1436 {
1796 HitTestResult touchHit = hitTestResultForWindowPos(position); 1437 HitTestResult touchHit = hitTestResultForWindowPos(position);
1797 1438
1798 if (touchHit.isContentEditable()) 1439 if (touchHit.isContentEditable())
1799 return false; 1440 return false;
1800 1441
1801 Node* node = touchHit.innerNode(); 1442 Node* node = touchHit.innerNode();
1802 if (!node || !node->isTextNode()) 1443 if (!node || !node->isTextNode())
1803 return false; 1444 return false;
(...skipping 15 matching lines...) Expand all
1819 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState, 1460 void WebViewImpl::setVisibilityState(WebPageVisibilityState visibilityState,
1820 bool isInitialState) { 1461 bool isInitialState) {
1821 if (!page()) 1462 if (!page())
1822 return; 1463 return;
1823 1464
1824 ASSERT(visibilityState == WebPageVisibilityStateVisible || visibilityState = = WebPageVisibilityStateHidden); 1465 ASSERT(visibilityState == WebPageVisibilityStateVisible || visibilityState = = WebPageVisibilityStateHidden);
1825 m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int> (visibilityState)), isInitialState); 1466 m_page->setVisibilityState(static_cast<PageVisibilityState>(static_cast<int> (visibilityState)), isInitialState);
1826 } 1467 }
1827 1468
1828 } // namespace blink 1469 } // namespace blink
OLDNEW
« sky/engine/platform/scroll/ScrollableArea.h ('K') | « sky/engine/web/WebViewImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698