Today's Menu  Portugal
journal and plan nutrition
Instance Methods | Protected Types | Properties | List of all members
Y3WebView Class Reference

#import <Y3WebView.h>

Inheritance diagram for Y3WebView:
Inheritance graph
[legend]
Collaboration diagram for Y3WebView:
Collaboration graph
[legend]

Instance Methods

(instancetype) - initWithFrame:andDelegate:
 
(void) - becomeResponder:
 
(void) - stirJavascript
 
(void) - scanPageForTitle
 
(void) - scanPageForIngredients
 
(void) - scanPageForInstruction
 
(void) - updateWebControls
 
(void) - captureClicked: [implementation]
 
(void) - handleTapGesture: [implementation]
 
(void) - reformForKeyboard [implementation]
 
(void) - goBack [implementation]
 
(void) - goForward [implementation]
 
(void) - loadRequest: [implementation]
 
(void) - goEditCopy [implementation]
 
(void) - webView:didFinishNavigation: [implementation]
 
(void) - webView:didCommitNavigation: [implementation]
 
(void) - webView:didStartProvisionalNavigation: [implementation]
 
(void) - webView:decidePolicyForNavigationResponse:decisionHandler: [implementation]
 
(void) - webView:decidePolicyForNavigationAction:decisionHandler: [implementation]
 
(void) - logNavigationAction: [implementation]
 

Protected Types

enum  MenuItemSegment { ReturnBasic, ReturnTitle, ReturnIngredients, ReturnInstructions }
 

Properties

Y3WebViewResponderwebView
 
U4WebControlsViewwebControls
 

Detailed Description

This view contains U4WebViewControls to control the WKWwbView, and a subclass of the WKWebView instance used (subclassing necessary to catch first responder notices).

Definition at line 32 of file Y3WebView.h.

Member Enumeration Documentation

◆ MenuItemSegment

- (enum) MenuItemSegment
protected
Enumerator
ReturnBasic 
ReturnTitle 
ReturnIngredients 
ReturnInstructions 

Definition at line 37 of file Y3WebView.h.

Method Documentation

◆ becomeResponder:()

- (void) becomeResponder: (BOOL)  flag

Definition at line 317 of file Y3WebView.m.

317  : (BOOL)flag {
318 
319  [_webControls focusAvailable:flag];
320 }

◆ captureClicked:()

- (void) captureClicked: (id)  sender
implementation

Definition at line 297 of file Y3WebView.m.

297  :(id)sender
298 {
299  NSLog(@"captureClicked");
300 }

◆ goBack()

- (void) goBack
implementation

Definition at line 341 of file Y3WebView.m.

342 {
343  NSLog(@"Y3WebView.goBack");
344  [_webView goBack];
345 }

◆ goEditCopy()

- (void) goEditCopy
implementation

Definition at line 361 of file Y3WebView.m.

362 {
363  NSLog(@"Y3WebView.goEditCopy");
364  [y3Delegate fireSnippetScreen];
365 }

◆ goForward()

- (void) goForward
implementation

Definition at line 346 of file Y3WebView.m.

347 {
348  NSLog(@"Y3WebView.goForward");
349  [_webView goForward];
350 }

◆ handleTapGesture:()

- (void) handleTapGesture: (UIGestureRecognizer *)  gesture
implementation

Definition at line 302 of file Y3WebView.m.

302  :(UIGestureRecognizer *)gesture
303 {
304  NSLog(@"Y3WebView.handleTapGesture: tap recognized");
305 
306  CGPoint tapLocation = [gesture locationInView:_webView];
307 
308  CGRect targetRect = CGRectMake(tapLocation.x, tapLocation.y, 0.0f, 0.0f);
309  [[UIMenuController sharedMenuController] setTargetRect:targetRect inView:_webView];
310 
311  UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Capture" action:@selector(captureClicked:)];
312  [[UIMenuController sharedMenuController] setMenuItems:@[menuItem]];
313 
314  [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
315 }
MenuItem * menuItem

◆ initWithFrame:andDelegate:()

- (instancetype) initWithFrame: (CGRect)  frame
andDelegate: (id<Y3WebViewDelegate>)  delegate 

this class contains the web navigation control bar and the web view

Definition at line 226 of file Y3WebView.m.

226  :(CGRect)frame andDelegate:(id<Y3WebViewDelegate>)delegate
227 {
228  self = [super initWithFrame:frame];
229  if (self) {
230  CGRect totalFrame = self.frame;
231 
232  CGRect controlsViewFrame = CGRectMake(10, 0, totalFrame.size.width - 20, 68.0);
233  _webControls = [[U4WebControlsView alloc] initWithFrame:controlsViewFrame andDelegate:self];
234  [_webControls appear:controlsViewFrame];
235  [_webControls setBackgroundColor:[UIColor lightGrayColor]];
236 
237  float controlsHeight = 70.0;
238  CGRect webViewFrame = CGRectMake(totalFrame.size.width * 0.01,
239  controlsHeight,
240  totalFrame.size.width * 0.98,
241  totalFrame.size.height - controlsHeight);
242 
243  WKPreferences *prefers = [[WKPreferences alloc] init];
244  [prefers setJavaScriptEnabled:YES];
245  [prefers setJavaScriptCanOpenWindowsAutomatically:YES];
246 
247 
248 //let contentController = WKUserContentController()
249 //let scriptSource = "document.body.style.backgroundColor = `red`;"
250 //let script = WKUserScript(source: scriptSource, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
251 //contentController.addUserScript(script)
252 //
253 //let config = WKWebViewConfiguration()
254 //config.userContentController = contentController
255 //
256 //let webView = WKWebView(frame: .zero, configuration: config)
257 
258  // create message handlers named "logging" and "newSelectionDetected"
259  WKUserContentController *ucc = [[WKUserContentController alloc] init];
260 // [ucc addScriptMessageHandler:delegate name:@"logging"];
261 // [ucc addScriptMessageHandler:delegate name:@"newSelectionDetected"] ;
262 
263  // assign usercontentcontroller to configuration
264  WKWebViewConfiguration *configur = [[WKWebViewConfiguration alloc] init];
265  [configur setPreferences:prefers];
266  [configur setUserContentController:ucc];
267  configur.showConsole = YES;
268 
269  _webView = [[Y3WebViewResponder alloc] initWithFrame:webViewFrame configuration:configur andControllerDelegate:delegate];
270 
271  y3Delegate = delegate;
272  _webView.navigationDelegate = delegate;
273  _webView.UIDelegate = delegate;
274 
275 
276 // Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Y3WebViewResponder 0x7f98bd002e00> valueForUndefinedKey:]: this class is not key value coding-compliant for the key documentView.'
277 // JSContext *ctx = [_webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
278 // ctx[@"console"][@"log"] = ^(JSValue * msg) {
279 // NSLog(@"JavaScript %@ log message: %@", [JSContext currentContext], msg);
280 // };
281 
282 
283 
284  // UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
285  // [webView addGestureRecognizer:tapRecognizer];
286 
287  [self addSubview:_webControls];
288  [self addSubview:_webView];
289  }
290  return self;
291 }
id< U7ParamEditControlDelegate > delegate

◆ loadRequest:()

- (void) loadRequest: (NSURLRequest *)  requestURL
implementation

Definition at line 356 of file Y3WebView.m.

356  : (NSURLRequest *)requestURL
357 {
358  NSLog(@"Y3WebView.loadRequest");
359  [_webView loadRequest:requestURL];
360 }

◆ logNavigationAction:()

- (void) logNavigationAction: (WKNavigationAction *)  navigationAction
implementation

Definition at line 442 of file Y3WebView.m.

442  : (WKNavigationAction *)navigationAction
443 {
444  NSLog(@" request: %@", navigationAction.request);
445  NSLog(@" source frame: %@", navigationAction.sourceFrame);
446  NSLog(@" target frame: %@", navigationAction.targetFrame);
447  if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
448  NSLog(@" WKNavigationTypeLinkActivated");
449  }
450  if (navigationAction.navigationType == WKNavigationTypeFormSubmitted) {
451  NSLog(@" WKNavigationTypeFormSubmitted");
452  }
453  if (navigationAction.navigationType == WKNavigationTypeBackForward) {
454  NSLog(@" WKNavigationTypeBackForward");
455  }
456  if (navigationAction.navigationType == WKNavigationTypeReload) {
457  NSLog(@" WKNavigationTypeReload");
458  }
459  if (navigationAction.navigationType == WKNavigationTypeFormResubmitted) {
460  NSLog(@" WKNavigationTypeFormResubmitted");
461  }
462  if (navigationAction.navigationType == WKNavigationTypeOther) {
463  NSLog(@" WKNavigationTypeOther");
464  }
465 }

◆ reformForKeyboard()

- (void) reformForKeyboard
implementation

Definition at line 321 of file Y3WebView.m.

322 {
323  NSLog(@"Y3WebView.reformForKeyboard: NO-OP");
324 //
325 // CGRect totalFrame = self.frame;
326 // CGFloat height;
327 // if (flag) {
328 // height = totalFrame.size.height * 0.38;
329 // } else {
330 // height = totalFrame.size.height * 0.88;
331 // }
332 //
333 // CGRect webViewFrame = CGRectMake(totalFrame.size.width * 0.01,
334 // totalFrame.size.height * 0.10,
335 // totalFrame.size.width * 0.98,
336 // height);
337 //
338 // [_webView setFrame:webViewFrame];
339 // [self setNeedsDisplay];
340 }

◆ scanPageForIngredients()

- (void) scanPageForIngredients

Definition at line 373 of file Y3WebView.m.

374 {
375  NSLog(@"Y3WebView.scanPageForIngredients");
376  [_webView exerciseJavascriptScanForIngredients];
377 }

◆ scanPageForInstruction()

- (void) scanPageForInstruction

Definition at line 378 of file Y3WebView.m.

379 {
380  NSLog(@"Y3WebView.scanPageForInstruction");
381  [_webView exerciseJavascriptScanForInstruction];
382 }

◆ scanPageForTitle()

- (void) scanPageForTitle

Definition at line 368 of file Y3WebView.m.

369 {
370  NSLog(@"Y3WebView.scanPageForTitle");
371  [_webView exerciseJavascriptScanForTitle];
372 }

◆ stirJavascript()

- (void) stirJavascript

Definition at line 351 of file Y3WebView.m.

352 {
353  NSLog(@"Y3WebView.stirJavascript");
354  [_webView exerciseJavascriptSendSelection];
355  }

◆ updateWebControls()

- (void) updateWebControls

Definition at line 292 of file Y3WebView.m.

293 {
294  [_webControls update:_webView];
295 }

◆ webView:decidePolicyForNavigationAction:decisionHandler:()

- (void) webView: (WKWebView *)  webView
decidePolicyForNavigationAction: (WKNavigationAction *)  navigationAction
decisionHandler: (void(^)(WKNavigationActionPolicy))  decisionHandler 
implementation

Definition at line 419 of file Y3WebView.m.

419  :(WKWebView *)webView
420  decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
421  decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
422 
423  NSURLRequest *request = navigationAction.request;
424  fileURL = request.URL;
425 
426  // HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
427  // UINavigationController *vc = [[UINavigationController alloc] initWithRootViewController:dlvc];
428  // vc.transitioningDelegate = self;
429  // dlvc.delegate = self;
430 
431  NSLog(@"Y3WebView.decidePolicyForNavigationAction: ~~~~~~~~~~~~~~~~~~~~~~");
432  [self logNavigationAction:navigationAction];
433  if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
434 
435  }
436 
437  if (decisionHandler) {
438  decisionHandler(WKNavigationActionPolicyAllow);
439  }
440 }
NSURL * fileURL
Definition: Y3WebView.m:219
Y3WebViewResponder * webView
Definition: Y3WebView.h:34

◆ webView:decidePolicyForNavigationResponse:decisionHandler:()

- (void) webView: (WKWebView *)  webView
decidePolicyForNavigationResponse: (WKNavigationResponse *)  navigationResponse
decisionHandler: (void(^)(WKNavigationResponsePolicy))  decisionHandler 
implementation

Definition at line 403 of file Y3WebView.m.

403  :(WKWebView *)webView
404  decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse
405  decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
406 
407  NSHTTPURLResponse *response = (NSHTTPURLResponse *)navigationResponse.response;
408  NSArray *cookies =[NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:response.URL];
409  for (NSHTTPCookie *cookie in cookies) {
410  [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
411  }
412 
413  decisionHandler(WKNavigationResponsePolicyAllow);
414  NSLog(@"Y3WebView.decidePolicyForNavigationResponse: ALLOW");
415 }
Y3WebViewResponder * webView
Definition: Y3WebView.h:34

◆ webView:didCommitNavigation:()

- (void) webView: (WKWebView *)  webView
didCommitNavigation: (WKNavigation *)  navigation 
implementation

Definition at line 392 of file Y3WebView.m.

392  :(WKWebView *)webView
393 didCommitNavigation:(WKNavigation *)navigation
394 {
395  NSLog(@"Y3WebView.didCommitNavigation: active URL: %@", webView.URL.description);
396 }
Y3WebViewResponder * webView
Definition: Y3WebView.h:34

◆ webView:didFinishNavigation:()

- (void) webView: (WKWebView *)  webViewHere
didFinishNavigation: (WKNavigation *)  navigation 
implementation

Definition at line 385 of file Y3WebView.m.

385  :(WKWebView *)webViewHere didFinishNavigation:(WKNavigation *)navigation
386 {
387  NSLog(@"Y3WebView.didFinishNavigation");
388  assert(NO);
389  [_webControls update: webViewHere];
390 }

◆ webView:didStartProvisionalNavigation:()

- (void) webView: (WKWebView *)  webView
didStartProvisionalNavigation: (null_unspecified WKNavigation *)  navigation 
implementation

Definition at line 398 of file Y3WebView.m.

398  :(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation
399 {
400  NSLog(@"Y3WebView.didStartProvisionalNavigation: active URL: %@", webView.URL.description);
401 }
Y3WebViewResponder * webView
Definition: Y3WebView.h:34

Property Documentation

◆ webControls

- (U4WebControlsView*) webControls
readwritenonatomicstrong

Definition at line 35 of file Y3WebView.h.

◆ webView

- (Y3WebViewResponder*) webView
readwritenonatomicstrong

Definition at line 34 of file Y3WebView.h.


The documentation for this class was generated from the following files: