• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to avoid user interaction in WebView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to avoid user interaction in WebView


  • Subject: How to avoid user interaction in WebView
  • From: Juanjo Conti <email@hidden>
  • Date: Fri, 30 Jan 2015 12:47:32 -0300

Hi! This is my first email in this list. I'm working with Cocoa (using
Swift) on a Mac Os X screensaver.

I'd like to use a WebView to show different web pages but I don't want the
user to be able to interact with the page. This is: no clicking, no
scrolling, no keystrokes firing events in the web pages...

How can I achieve this?

I was able to do

window?.ignoresMouseEvents = true

to avoid user scrolling

and

    // WebUIDelegate Protocol method

    override func webView(_: WebView, contextMenuItemsForElement: [NSObject
: AnyObject]!, defaultMenuItems: [AnyObject]!) -> [AnyObject]! {
        return nil
    }
to to avoid right click on WebView to show a context menu.

But this is not enough. Key strokes are a problem. For example, if I'm
showing Twitter web page and a user press 'n', Twitter opens a text area
and you are allow to type there and effectively tweet.

So what I'm considering now is to have a transparent view in front of the
WebView to make it capture all the user interaction. I was able to place
this TransparentView on top of the WebView but events are still reaching
the WebView. This is my current TransparentView implementation:

class TransparentView : NSView {

    override func drawRect(dirtyRect: NSRect) {
        super.drawRect(dirtyRect)

        //NSColor.clearColor().set()
        var green = NSColor(calibratedRed: 0, green: 1, blue: 0, alpha: 0.5)
        green.set()
        NSBezierPath.fillRect(bounds)
    }

    override func keyDown(theEvent: NSEvent) {}

    override func hitTest(aPoint: NSPoint) -> NSView? {
        return nil
    }

    override func becomeFirstResponder() -> Bool {
        return true
    }

    override func acceptsFirstMouse(_ : NSEvent) -> Bool {
        return true
    }

    override var canBecomeKeyView: Bool { return true }
}

You can see there my tries to avoid events reach WebView.

What do you think? Am I wrong in the way I'm trying to solve the problem?
If not, how can I make the TransparentView to catch all the events?

Thanks in advance,

--

Juanjo Conti <jjconti <http://goog_2023646312>@carouselapps.com
<email@hidden>>

--
Carousel Apps Limited, registered in England & Wales with registered number
7689440 and registered office Unit 2 Artbrand Studios, 7 Leathermarket
Street, London SE1 3HN. Any communication sent by or on behalf of Carousel
App Ltd or any of its subsidiary, holding or affiliated companies or
entities (together "Watu") is confidential and may be privileged or
otherwise protected. If you receive it in error please inform us and then
delete it from your system. You should not copy it or disclose its contents
to anyone. Messages sent to and from Watu may be monitored to ensure
compliance with our internal policies and to protect our business. Emails
are not secure and cannot be guaranteed to be error free. Anyone who
communicates with us by email is taken to accept these risks.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How to avoid user interaction in WebView
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Program Crash
  • Next by Date: Re: Program Crash
  • Previous by thread: Re: Program Crash
  • Next by thread: Re: How to avoid user interaction in WebView
  • Index(es):
    • Date
    • Thread