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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 1137653005: MacViews: Implement Tooltips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: learn to alphabet tapted Created 5 years, 7 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
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/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 2721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2732 BrowserAccessibilityCocoa* focused_item_cocoa = 2732 BrowserAccessibilityCocoa* focused_item_cocoa =
2733 focused_item->ToBrowserAccessibilityCocoa(); 2733 focused_item->ToBrowserAccessibilityCocoa();
2734 DCHECK(focused_item_cocoa); 2734 DCHECK(focused_item_cocoa);
2735 if (focused_item_cocoa) 2735 if (focused_item_cocoa)
2736 return focused_item_cocoa; 2736 return focused_item_cocoa;
2737 } 2737 }
2738 } 2738 }
2739 return [super accessibilityFocusedUIElement]; 2739 return [super accessibilityFocusedUIElement];
2740 } 2740 }
2741 2741
2742 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm
2743 // with minor modifications for code style and commenting.
2744 //
2745 // The 'public' interface is -setToolTipAtMousePoint:. This differs from
2746 // -setToolTip: in that the updated tooltip takes effect immediately,
2747 // without the user's having to move the mouse out of and back into the view.
2748 //
2749 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to
2750 // the view, which in turn requires overriding some internal tracking-rect
2751 // methods (to keep track of its owner & userdata, which need to be filled out
2752 // in the fake events.) --snej 7/6/09
2753
2754
2755 /*
2756 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
2757 * (C) 2006, 2007 Graham Dennis (graham.dennis@gmail.com)
2758 *
2759 * Redistribution and use in source and binary forms, with or without
2760 * modification, are permitted provided that the following conditions
2761 * are met:
2762 *
2763 * 1. Redistributions of source code must retain the above copyright
2764 * notice, this list of conditions and the following disclaimer.
2765 * 2. Redistributions in binary form must reproduce the above copyright
2766 * notice, this list of conditions and the following disclaimer in the
2767 * documentation and/or other materials provided with the distribution.
2768 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
2769 * its contributors may be used to endorse or promote products derived
2770 * from this software without specific prior written permission.
2771 *
2772 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
2773 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2774 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2775 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
2776 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2777 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2778 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2779 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2780 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2781 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2782 */
2783
2784 // Any non-zero value will do, but using something recognizable might help us
2785 // debug some day.
2786 static const NSTrackingRectTag kTrackingRectTag = 0xBADFACE;
2787
2788 // Override of a public NSView method, replacing the inherited functionality.
2789 // See above for rationale.
2790 - (NSTrackingRectTag)addTrackingRect:(NSRect)rect
2791 owner:(id)owner
2792 userData:(void *)data
2793 assumeInside:(BOOL)assumeInside {
2794 DCHECK(trackingRectOwner_ == nil);
2795 trackingRectOwner_ = owner;
2796 trackingRectUserData_ = data;
2797 return kTrackingRectTag;
2798 }
2799
2800 // Override of (apparently) a private NSView method(!) See above for rationale.
2801 - (NSTrackingRectTag)_addTrackingRect:(NSRect)rect
2802 owner:(id)owner
2803 userData:(void *)data
2804 assumeInside:(BOOL)assumeInside
2805 useTrackingNum:(int)tag {
2806 DCHECK(tag == 0 || tag == kTrackingRectTag);
2807 DCHECK(trackingRectOwner_ == nil);
2808 trackingRectOwner_ = owner;
2809 trackingRectUserData_ = data;
2810 return kTrackingRectTag;
2811 }
2812
2813 // Override of (apparently) a private NSView method(!) See above for rationale.
2814 - (void)_addTrackingRects:(NSRect *)rects
2815 owner:(id)owner
2816 userDataList:(void **)userDataList
2817 assumeInsideList:(BOOL *)assumeInsideList
2818 trackingNums:(NSTrackingRectTag *)trackingNums
2819 count:(int)count {
2820 DCHECK(count == 1);
2821 DCHECK(trackingNums[0] == 0 || trackingNums[0] == kTrackingRectTag);
2822 DCHECK(trackingRectOwner_ == nil);
2823 trackingRectOwner_ = owner;
2824 trackingRectUserData_ = userDataList[0];
2825 trackingNums[0] = kTrackingRectTag;
2826 }
2827
2828 // Override of a public NSView method, replacing the inherited functionality.
2829 // See above for rationale.
2830 - (void)removeTrackingRect:(NSTrackingRectTag)tag {
2831 if (tag == 0)
2832 return;
2833
2834 if (tag == kTrackingRectTag) {
2835 trackingRectOwner_ = nil;
2836 return;
2837 }
2838
2839 if (tag == lastToolTipTag_) {
2840 [super removeTrackingRect:tag];
2841 lastToolTipTag_ = 0;
2842 return;
2843 }
2844
2845 // If any other tracking rect is being removed, we don't know how it was
2846 // created and it's possible there's a leak involved (see Radar 3500217).
2847 NOTREACHED();
2848 }
2849
2850 // Override of (apparently) a private NSView method(!)
2851 - (void)_removeTrackingRects:(NSTrackingRectTag *)tags count:(int)count {
2852 for (int i = 0; i < count; ++i) {
2853 int tag = tags[i];
2854 if (tag == 0)
2855 continue;
2856 DCHECK(tag == kTrackingRectTag);
2857 trackingRectOwner_ = nil;
2858 }
2859 }
2860
2861 // Sends a fake NSMouseExited event to the view for its current tracking rect.
2862 - (void)_sendToolTipMouseExited {
2863 // Nothing matters except window, trackingNumber, and userData.
2864 int windowNumber = [[self window] windowNumber];
2865 NSEvent* fakeEvent = [NSEvent enterExitEventWithType:NSMouseExited
2866 location:NSZeroPoint
2867 modifierFlags:0
2868 timestamp:0
2869 windowNumber:windowNumber
2870 context:NULL
2871 eventNumber:0
2872 trackingNumber:kTrackingRectTag
2873 userData:trackingRectUserData_];
2874 [trackingRectOwner_ mouseExited:fakeEvent];
2875 }
2876
2877 // Sends a fake NSMouseEntered event to the view for its current tracking rect.
2878 - (void)_sendToolTipMouseEntered {
2879 // Nothing matters except window, trackingNumber, and userData.
2880 int windowNumber = [[self window] windowNumber];
2881 NSEvent* fakeEvent = [NSEvent enterExitEventWithType:NSMouseEntered
2882 location:NSZeroPoint
2883 modifierFlags:0
2884 timestamp:0
2885 windowNumber:windowNumber
2886 context:NULL
2887 eventNumber:0
2888 trackingNumber:kTrackingRectTag
2889 userData:trackingRectUserData_];
2890 [trackingRectOwner_ mouseEntered:fakeEvent];
2891 }
2892
2893 // Sets the view's current tooltip, to be displayed at the current mouse
2894 // location. (This does not make the tooltip appear -- as usual, it only
2895 // appears after a delay.) Pass null to remove the tooltip.
2896 - (void)setToolTipAtMousePoint:(NSString *)string {
2897 NSString *toolTip = [string length] == 0 ? nil : string;
2898 if ((toolTip && toolTip_ && [toolTip isEqualToString:toolTip_]) ||
2899 (!toolTip && !toolTip_)) {
2900 return;
2901 }
2902
2903 if (toolTip_) {
2904 [self _sendToolTipMouseExited];
2905 }
2906
2907 toolTip_.reset([toolTip copy]);
2908
2909 if (toolTip) {
2910 // See radar 3500217 for why we remove all tooltips
2911 // rather than just the single one we created.
2912 [self removeAllToolTips];
2913 NSRect wideOpenRect = NSMakeRect(-100000, -100000, 200000, 200000);
2914 lastToolTipTag_ = [self addToolTipRect:wideOpenRect
2915 owner:self
2916 userData:NULL];
2917 [self _sendToolTipMouseEntered];
2918 }
2919 }
2920
2921 // NSView calls this to get the text when displaying the tooltip.
2922 - (NSString *)view:(NSView *)view
2923 stringForToolTip:(NSToolTipTag)tag
2924 point:(NSPoint)point
2925 userData:(void *)data {
2926 return [[toolTip_ copy] autorelease];
2927 }
2928
2929 // Below is our NSTextInputClient implementation. 2742 // Below is our NSTextInputClient implementation.
2930 // 2743 //
2931 // When WebHTMLView receives a NSKeyDown event, WebHTMLView calls the following 2744 // When WebHTMLView receives a NSKeyDown event, WebHTMLView calls the following
2932 // functions to process this event. 2745 // functions to process this event.
2933 // 2746 //
2934 // [WebHTMLView keyDown] -> 2747 // [WebHTMLView keyDown] ->
2935 // EventHandler::keyEvent() -> 2748 // EventHandler::keyEvent() ->
2936 // ... 2749 // ...
2937 // [WebEditorClient handleKeyboardEvent] -> 2750 // [WebEditorClient handleKeyboardEvent] ->
2938 // [WebHTMLView _interceptEditingKeyEvent] -> 2751 // [WebHTMLView _interceptEditingKeyEvent] ->
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
3484 3297
3485 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3298 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3486 // regions that are not draggable. (See ControlRegionView in 3299 // regions that are not draggable. (See ControlRegionView in
3487 // native_app_window_cocoa.mm). This requires the render host view to be 3300 // native_app_window_cocoa.mm). This requires the render host view to be
3488 // draggable by default. 3301 // draggable by default.
3489 - (BOOL)mouseDownCanMoveWindow { 3302 - (BOOL)mouseDownCanMoveWindow {
3490 return YES; 3303 return YES;
3491 } 3304 }
3492 3305
3493 @end 3306 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698