Changeset 79914 in webkit


Ignore:
Timestamp:
Feb 28, 2011 1:39:27 PM (13 years ago)
Author:
weinig@apple.com
Message:

WK2 Context Menus - Implement LookUpInDictionary
https://bugs.webkit.org/show_bug.cgi?id=55405

Reviewed by Brady Eidson.

  • Shared/DictionaryPopupInfo.cpp:

(WebKit::DictionaryPopupInfo::encode):
(WebKit::DictionaryPopupInfo::decode):

  • Shared/DictionaryPopupInfo.h:

Add type to differentiate between HotKey and ContextMenu triggered
dictionary popups. This is necessary since HotKey triggered ones want
to override the style to always be overlay.

  • UIProcess/API/mac/PageClientImpl.mm:

(WebKit::PageClientImpl::didPerformDictionaryLookup):
Only force the overlay style for HotKey triggered dictionary lookups.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForRange):
Factor out shared functionality into performDictionaryLookupForRange.

  • WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:

(WebKit::WebContextMenuClient::lookUpInDictionary):
Get selected range and call newly factored out performDictionaryLookupForRange.

Location:
trunk/Source/WebKit2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r79891 r79914  
     12011-02-28  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Brady Eidson.
     4
     5        WK2 Context Menus - Implement LookUpInDictionary
     6        https://bugs.webkit.org/show_bug.cgi?id=55405
     7
     8        * Shared/DictionaryPopupInfo.cpp:
     9        (WebKit::DictionaryPopupInfo::encode):
     10        (WebKit::DictionaryPopupInfo::decode):
     11        * Shared/DictionaryPopupInfo.h:
     12        Add type to differentiate between HotKey and ContextMenu triggered
     13        dictionary popups. This is necessary since HotKey triggered ones want
     14        to override the style to always be overlay.
     15
     16        * UIProcess/API/mac/PageClientImpl.mm:
     17        (WebKit::PageClientImpl::didPerformDictionaryLookup):
     18        Only force the overlay style for HotKey triggered dictionary lookups.
     19
     20        * WebProcess/WebPage/WebPage.h:
     21        * WebProcess/WebPage/mac/WebPageMac.mm:
     22        (WebKit::WebPage::performDictionaryLookupAtLocation):
     23        (WebKit::WebPage::performDictionaryLookupForRange):
     24        Factor out shared functionality into performDictionaryLookupForRange.
     25
     26        * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
     27        (WebKit::WebContextMenuClient::lookUpInDictionary):
     28        Get selected range and call newly factored out performDictionaryLookupForRange.
     29
    1302011-02-28  Anders Carlsson  <andersca@apple.com>
    231
  • trunk/Source/WebKit2/Shared/DictionaryPopupInfo.cpp

    r79886 r79914  
    3535    encoder->encode(origin);
    3636    encoder->encode(fontInfo);
     37    encoder->encodeEnum(type);
    3738}
    3839
     
    4344    if (!decoder->decode(result.fontInfo))
    4445        return false;
     46    if (!decoder->decodeEnum(result.type))
     47        return false;
    4548    return true;
    4649}
  • trunk/Source/WebKit2/Shared/DictionaryPopupInfo.h

    r79886 r79914  
    4141    static bool decode(CoreIPC::ArgumentDecoder*, DictionaryPopupInfo&);
    4242
     43    enum Type {
     44        ContextMenu,
     45        HotKey
     46    };
     47
    4348    WebCore::FloatPoint origin;
    4449    FontInfo fontInfo;
     50    Type type;
    4551};
    4652
  • trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm

    r79886 r79914  
    425425    textBaselineOrigin.y += [font ascender];
    426426   
    427     NSDictionary *options = [NSDictionary dictionaryWithObject:NSDefinitionPresentationTypeOverlay forKey:NSDefinitionPresentationTypeKey];
     427    // If the dictionary lookup is being triggered by a hot key, force the overlay style.
     428    NSDictionary *options = (dictionaryPopupInfo.type == DictionaryPopupInfo::HotKey) ? [NSDictionary dictionaryWithObject:NSDefinitionPresentationTypeOverlay forKey:NSDefinitionPresentationTypeKey] : 0;
    428429    [m_wkView showDefinitionForAttributedString:attributedString.get() range:NSMakeRange(0, [attributedString.get() length]) options:options baselineOriginProvider:^(NSRange adjustedRange) { return (NSPoint)textBaselineOrigin; }];
    429430}
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm

    r79335 r79914  
    2727#import "WebContextMenuClient.h"
    2828
     29#import "DictionaryPopupInfo.h"
     30#import "WebCoreArgumentCoders.h"
    2931#import "WebPage.h"
     32#import "WebPageProxyMessages.h"
    3033#import <WebCore/Frame.h>
    31 #include <WebCore/NotImplemented.h>
     34#import <WebCore/FrameView.h>
    3235#import <WebCore/Page.h>
    3336#import <wtf/text/WTFString.h>
     
    3740namespace WebKit {
    3841
    39 void WebContextMenuClient::lookUpInDictionary(Frame*)
     42void WebContextMenuClient::lookUpInDictionary(Frame* frame)
    4043{
    41     // FIXME: <rdar://problem/8750610> - Implement
    42     notImplemented();
     44    RefPtr<Range> selectedRange = frame->selection()->selection().toNormalizedRange();
     45    if (!selectedRange)
     46        return;
     47
     48    m_page->performDictionaryLookupForRange(DictionaryPopupInfo::ContextMenu, frame, selectedRange.get());
    4349}
    4450
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r79863 r79914  
    5858
    5959#if PLATFORM(MAC)
     60#include "DictionaryPopupInfo.h"
    6061#include <wtf/RetainPtr.h>
    6162OBJC_CLASS AccessibilityWebPageObject;
     
    308309
    309310#if PLATFORM(MAC)
     311    void performDictionaryLookupForRange(DictionaryPopupInfo::Type, WebCore::Frame*, WebCore::Range*);
     312
    310313    bool isSpeaking();
    311314    void speak(const String&);
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r79886 r79914  
    2929#import "AccessibilityWebPageObject.h"
    3030#import "DataReference.h"
    31 #import "DictionaryPopupInfo.h"
    3231#import "PluginView.h"
    3332#import "WebCoreArgumentCoders.h"
     
    287286        return;
    288287
    289     RenderObject* renderer = finalRange->startContainer()->renderer();
     288    performDictionaryLookupForRange(DictionaryPopupInfo::HotKey, frame, finalRange.get());
     289}
     290
     291void WebPage::performDictionaryLookupForRange(DictionaryPopupInfo::Type type, Frame* frame, Range* range)
     292{
     293    String rangeText = range->text();
     294    if (rangeText.stripWhiteSpace().isEmpty())
     295        return;
     296   
     297    RenderObject* renderer = range->startContainer()->renderer();
    290298    RenderStyle* style = renderer->style();
    291299    NSFont *font = style->font().primaryFont()->getNSFont();
    292300    if (!font)
    293301        return;
    294 
     302   
    295303    CFDictionaryRef fontDescriptorAttributes = (CFDictionaryRef)[[font fontDescriptor] fontAttributes];
    296304    if (!fontDescriptorAttributes)
     
    298306
    299307    Vector<FloatQuad> quads;
    300     finalRange->textQuads(quads);
     308    range->textQuads(quads);
    301309    if (quads.isEmpty())
    302310        return;
    303 
    304     IntRect finalRangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
    305 
     311   
     312    IntRect rangeRect = frame->view()->contentsToWindow(quads[0].enclosingBoundingBox());
     313   
    306314    DictionaryPopupInfo dictionaryPopupInfo;
    307     dictionaryPopupInfo.origin = FloatPoint(finalRangeRect.x(), finalRangeRect.y());
     315    dictionaryPopupInfo.type = type;
     316    dictionaryPopupInfo.origin = FloatPoint(rangeRect.x(), rangeRect.y());
    308317    dictionaryPopupInfo.fontInfo.fontAttributeDictionary = fontDescriptorAttributes;
    309318
    310     send(Messages::WebPageProxy::DidPerformDictionaryLookup(finalRange->text(), dictionaryPopupInfo));
     319    send(Messages::WebPageProxy::DidPerformDictionaryLookup(rangeText, dictionaryPopupInfo));
    311320}
    312321
Note: See TracChangeset for help on using the changeset viewer.