Reviewed by Beth and Adam
Support for displaying tooltips for bad grammar. Currently this always displays the same tooltip;
next I'll make it use a string that's relevant for a specific grammar error.
* WebCore.exp:
export symbol for spellingToolTip function
* rendering/HitTestResult.h:
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::spellingToolTip):
new function, returns the string to be used in a tool tip that describes the questionable grammar
* rendering/InlineTextBox.h:
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paintSpellingOrGrammarMarker):
now takes a style and font, needed to compute the rect representing the range containing
questionable grammar. Computes the rect and associates it with the marker.
(WebCore::InlineTextBox::paintDocumentMarkers):
Pass in the style and font now needed by paintSpellingOrGrammarMarker
WebKit:
Reviewed by Beth and Adam
Display a tooltip when hovering over marked bad grammar.
* Misc/WebElementDictionary.m:
(+[WebElementDictionary initializeLookupTable]):
support spelling tool tip
(-[WebElementDictionary _spellingToolTip]):
new method, calls through to HitTestResult
* WebView/WebHTMLView.m:
(-[WebHTMLView _updateMouseoverWithEvent:]):
Check for a spelling tool tip; if found, prefer it over the other possible tool tips.
Check for empty strings instead of just nil strings being, since values from
WebElementDictionary are empty strings.
* WebView/WebViewPrivate.h:
declare new string constant WebElementSpellingToolTipKey
* WebView/WebView.mm:
define new string constant WebElementSpellingToolTipKey
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17501
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-10-31 John Sullivan <sullivan@apple.com>
+
+ Reviewed by Beth and Adam
+
+ Support for displaying tooltips for bad grammar. Currently this always displays the same tooltip;
+ next I'll make it use a string that's relevant for a specific grammar error.
+
+ * WebCore.exp:
+ export symbol for spellingToolTip function
+
+ * rendering/HitTestResult.h:
+ * rendering/HitTestResult.cpp:
+ (WebCore::HitTestResult::spellingToolTip):
+ new function, returns the string to be used in a tool tip that describes the questionable grammar
+
+ * rendering/InlineTextBox.h:
+ * rendering/InlineTextBox.cpp:
+ (WebCore::InlineTextBox::paintSpellingOrGrammarMarker):
+ now takes a style and font, needed to compute the rect representing the range containing
+ questionable grammar. Computes the rect and associates it with the marker.
+ (WebCore::InlineTextBox::paintDocumentMarkers):
+ Pass in the style and font now needed by paintSpellingOrGrammarMarker
+
2006-10-31 Adele Peterson <adele@apple.com>
Removed commented out variable from last checkin.
__ZNK7WebCore12RenderObject25backslashAsCurrencySymbolEv
__ZNK7WebCore13HitTestResult10isSelectedEv
__ZNK7WebCore13HitTestResult11boundingBoxEv
+__ZNK7WebCore13HitTestResult15spellingToolTipEv
__ZNK7WebCore13HitTestResult11targetFrameEv
__ZNK7WebCore13HitTestResult5titleEv
__ZNK7WebCore14DocumentLoader10isStoppingEv
return frame->selectionController()->contains(m_point);
}
+String HitTestResult::spellingToolTip() const
+{
+ // Return the tool tip string associated with this point
+ // FIXME: At the moment this returns the same hardwired string for all bad grammar rects. This needs to
+ // instead return an instance-specific string that was stashed away when the bad grammar was discovered.
+ // Checking it in now just to modularize the work a little.
+ Vector<IntRect> rects = m_innerNonSharedNode->document()->renderedRectsForMarkers(DocumentMarker::Grammar);
+ unsigned count = rects.size();
+ for (unsigned index = 0; index < count; ++index)
+ if (rects[index].contains(m_point))
+ return "Questionable grammar!";
+
+ return String();
+}
+
String HitTestResult::title() const
{
// Find the title in the nearest enclosing DOM node.
Frame* targetFrame() const;
IntRect boundingBox() const;
bool isSelected() const;
+ String spellingToolTip() const;
String title() const;
private:
}
}
-void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int _tx, int _ty, DocumentMarker marker, bool grammar)
+void InlineTextBox::paintSpellingOrGrammarMarker(GraphicsContext* pt, int _tx, int _ty, DocumentMarker marker, RenderStyle* style, const Font* f, bool grammar)
{
_tx += m_x;
_ty += m_y;
width = static_cast<RenderText*>(m_object)->width(paintStart, paintEnd - paintStart, textPos() + start, m_firstLine);
}
+ // Store rendered rects for bad grammar markers, so we can hit-test against it elsewhere in order to
+ // display a toolTip. We don't do this for misspelling markers.
+ if (grammar) {
+ int y = root()->selectionTop();
+ IntPoint startPoint = IntPoint(m_x + _tx, y + _ty);
+ TextStyle textStyle = TextStyle(textObject()->tabWidth(), textPos(), m_toAdd, m_reversed, m_dirOverride || style->visuallyOrdered());
+ int startPosition = max(marker.startOffset - m_start, (unsigned)0);
+ int endPosition = min(marker.endOffset - m_start, (unsigned)m_len);
+ TextRun run = TextRun(textObject()->string(), m_start, m_len, startPosition, endPosition);
+ IntRect markerRect = enclosingIntRect(f->selectionRectForText(run, textStyle, startPoint, root()->selectionHeight()));
+ object()->document()->setRenderedRectForMarker(object()->node(), marker, markerRect);
+ }
+
// IMPORTANT: The misspelling underline is not considered when calculating the text bounds, so we have to
// make sure to fit within those bounds. This means the top pixel(s) of the underline will overlap the
// bottom pixel(s) of the glyphs in smaller font sizes. The alternatives are to increase the line spacing (bad!!)
// marker intersects this run. Paint it.
switch (marker.type) {
case DocumentMarker::Spelling:
- paintSpellingOrGrammarMarker(pt, _tx, _ty, marker, false);
+ paintSpellingOrGrammarMarker(pt, _tx, _ty, marker, style, f, false);
break;
case DocumentMarker::Grammar:
- paintSpellingOrGrammarMarker(pt, _tx, _ty, marker, true);
+ paintSpellingOrGrammarMarker(pt, _tx, _ty, marker, style, f, true);
break;
case DocumentMarker::TextMatch:
paintTextMatchMarker(pt, _tx, _ty, marker, style, f);
void paintSelection(GraphicsContext*, int tx, int ty, RenderStyle*, const Font*);
void paintMarkedTextBackground(GraphicsContext*, int tx, int ty, RenderStyle*, const Font*, int startPos, int endPos);
void paintDocumentMarkers(GraphicsContext*, int tx, int ty, RenderStyle*, const Font*, bool background);
- void paintSpellingOrGrammarMarker(GraphicsContext*, int tx, int ty, DocumentMarker, bool grammar);
+ void paintSpellingOrGrammarMarker(GraphicsContext*, int tx, int ty, DocumentMarker, RenderStyle*, const Font*, bool grammar);
void paintTextMatchMarker(GraphicsContext*, int tx, int ty, DocumentMarker, RenderStyle*, const Font*);
void paintMarkedTextUnderline(GraphicsContext*, int tx, int ty, const MarkedTextUnderline&);
#if PLATFORM(MAC)
+2006-10-31 John Sullivan <sullivan@apple.com>
+
+ Reviewed by Beth and Adam
+
+ Display a tooltip when hovering over marked bad grammar.
+
+ * Misc/WebElementDictionary.m:
+ (+[WebElementDictionary initializeLookupTable]):
+ support spelling tool tip
+ (-[WebElementDictionary _spellingToolTip]):
+ new method, calls through to HitTestResult
+
+ * WebView/WebHTMLView.m:
+ (-[WebHTMLView _updateMouseoverWithEvent:]):
+ Check for a spelling tool tip; if found, prefer it over the other possible tool tips.
+ Check for empty strings instead of just nil strings being, since values from
+ WebElementDictionary are empty strings.
+
+ * WebView/WebViewPrivate.h:
+ declare new string constant WebElementSpellingToolTipKey
+ * WebView/WebView.mm:
+ define new string constant WebElementSpellingToolTipKey
+
2006-10-31 Beth Dakin <bdakin@apple.com>
Reviewed by Maciej.
addLookupKey(WebElementImageRectKey, @selector(_imageRect), WebElementSelf);
addLookupKey(WebElementImageURLKey, @selector(absoluteImageURL), WebElementInnerNonSharedNode);
addLookupKey(WebElementIsSelectedKey, @selector(_isSelected), WebElementSelf);
+ addLookupKey(WebElementSpellingToolTipKey, @selector(_spellingToolTip), WebElementSelf);
addLookupKey(WebElementTitleKey, @selector(_title), WebElementSelf);
addLookupKey(WebElementLinkURLKey, @selector(absoluteLinkURL), WebElementURLElement);
addLookupKey(WebElementLinkTargetFrameKey, @selector(_targetWebFrame), WebElementSelf);
return kit(webCoreFrame);
}
+- (NSString *)_spellingToolTip
+{
+ return _result->spellingToolTip();
+}
+
- (NSString *)_title
{
return _result->title();
[[view _webView] _mouseDidMoveOverElement:element modifierFlags:[event modifierFlags]];
// Set a tool tip; it won't show up right away but will if the user pauses.
- NSString *newToolTip = nil;
- if (_private->showsURLsInToolTips) {
+
+ // First priority is a potential toolTip representing a spelling or grammar error
+ NSString *newToolTip = [element objectForKey:WebElementSpellingToolTipKey];
+
+ // Next priority is a toolTip from a URL beneath the mouse (if preference is set to show those).
+ if ([newToolTip length] == 0 && _private->showsURLsInToolTips) {
DOMHTMLElement *domElement = [element objectForKey:WebElementDOMNodeKey];
+
+ // Get tooltip representing form action, if relevant
if ([domElement isKindOfClass:[DOMHTMLInputElement class]]) {
if ([[(DOMHTMLInputElement *)domElement type] isEqualToString:@"submit"])
newToolTip = [[(DOMHTMLInputElement *) domElement form] action];
}
- if (newToolTip == nil)
+
+ // Get tooltip representing link's URL
+ if ([newToolTip length] == 0)
newToolTip = [[element objectForKey:WebElementLinkURLKey] _web_userVisibleString];
}
- if (newToolTip == nil)
+
+ // Lastly we'll consider a tooltip for element with "title" attribute
+ if ([newToolTip length] == 0)
newToolTip = [element objectForKey:WebElementTitleKey];
+
[view _setToolTip:newToolTip];
[view release];
NSString *WebElementImageRectKey = @"WebElementImageRect";
NSString *WebElementImageURLKey = @"WebElementImageURL";
NSString *WebElementIsSelectedKey = @"WebElementIsSelected";
-NSString *WebElementTitleKey = @"WebElementTitle";
-NSString *WebElementLinkURLKey = @"WebElementLinkURL";
-NSString *WebElementLinkTargetFrameKey = @"WebElementTargetFrame";
NSString *WebElementLinkLabelKey = @"WebElementLinkLabel";
+NSString *WebElementLinkTargetFrameKey = @"WebElementTargetFrame";
NSString *WebElementLinkTitleKey = @"WebElementLinkTitle";
+NSString *WebElementLinkURLKey = @"WebElementLinkURL";
+NSString *WebElementSpellingToolTipKey = @"WebElementSpellingToolTip";
+NSString *WebElementTitleKey = @"WebElementTitle";
NSString *WebViewProgressStartedNotification = @"WebProgressStartedNotification";
NSString *WebViewProgressEstimateChangedNotification = @"WebProgressEstimateChangedNotification";
extern NSString *_WebMainFrameURLKey;
extern NSString *_WebMainFrameDocumentKey;
-extern NSString *WebElementTitleKey; // NSString of the title of the element (pending public, used by Safari)
+// pending public WebElementDictionary keys
+extern NSString *WebElementTitleKey; // NSString of the title of the element (used by Safari)
+extern NSString *WebElementSpellingToolTipKey; // NSString of a tooltip representing misspelling or bad grammar (used internally)
typedef enum {
WebDashboardBehaviorAlwaysSendMouseEventsToAllWindows,