Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 5 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 // Background color RGB values for the content view which is displayed when the | |
| 15 // |_webView| is offset from the screen due to user interaction. Displaying this | |
| 16 // background color is handled by UIWebView but not WKWebView, so it needs to be | |
| 17 // set in CRWWebViewContentView to support both. The color value matches that | |
| 18 // used by UIWebView. | |
| 19 const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 @interface CRWWebViewContentView () { | 12 @interface CRWWebViewContentView () { |
| 24 // The web view being shown. | 13 // The web view being shown. |
| 25 base::scoped_nsobject<UIView> _webView; | 14 base::scoped_nsobject<UIView> _webView; |
| 26 // The web view's scroll view. | 15 // The web view's scroll view. |
| 27 base::scoped_nsobject<UIScrollView> _scrollView; | 16 base::scoped_nsobject<UIScrollView> _scrollView; |
| 28 // Backs up property of the same name if |_webView| is a WKWebView. | 17 // Backs up property of the same name if |_webView| is a WKWebView. |
| 29 CGFloat _topContentPadding; | 18 CGFloat _topContentPadding; |
| 30 } | 19 } |
| 31 | 20 |
| 32 // Changes web view frame to match |self.bounds| and optionally accomodates for | 21 // Changes web view frame to match |self.bounds| and optionally accomodates for |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 NOTREACHED(); | 57 NOTREACHED(); |
| 69 return nil; | 58 return nil; |
| 70 } | 59 } |
| 71 | 60 |
| 72 - (void)didMoveToSuperview { | 61 - (void)didMoveToSuperview { |
| 73 [super didMoveToSuperview]; | 62 [super didMoveToSuperview]; |
| 74 if (self.superview) { | 63 if (self.superview) { |
| 75 self.autoresizingMask = | 64 self.autoresizingMask = |
| 76 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 65 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 77 [self addSubview:_webView]; | 66 [self addSubview:_webView]; |
| 78 self.backgroundColor = [UIColor colorWithRed:kBackgroundRGBComponents[0] | |
|
stuartmorgan
2016/02/11 17:04:34
Why don't we still need a background color on the
kkhorimoto
2016/02/11 18:27:24
I'm not sure what you mean about the web view draw
| |
| 79 green:kBackgroundRGBComponents[1] | |
| 80 blue:kBackgroundRGBComponents[2] | |
| 81 alpha:1.0]; | |
| 82 // The frame needs to be set immediately after the web view is added | 67 // The frame needs to be set immediately after the web view is added |
| 83 // as a subview. The change in the frame triggers drawing operations and | 68 // as a subview. The change in the frame triggers drawing operations and |
| 84 // if not done after it's added as a subview, the web view exhibits | 69 // if not done after it's added as a subview, the web view exhibits |
| 85 // strange behavior where clicks from certain web sites are not triggered. | 70 // strange behavior where clicks from certain web sites are not triggered. |
| 86 // The actual value of the frame doesn't matter as long as it's not | 71 // The actual value of the frame doesn't matter as long as it's not |
| 87 // CGRectZero. The CRWWebViewContentView's frame will be reset to a correct | 72 // CGRectZero. The CRWWebViewContentView's frame will be reset to a correct |
| 88 // value in a subsequent layout pass. | 73 // value in a subsequent layout pass. |
| 89 // TODO(crbug.com/577793): This is an undocumented and not-well-understood | 74 // TODO(crbug.com/577793): This is an undocumented and not-well-understood |
| 90 // workaround for this issue. | 75 // workaround for this issue. |
| 91 const CGRect kDummyRect = CGRectMake(10, 20, 30, 50); | 76 const CGRect kDummyRect = CGRectMake(10, 20, 30, 50); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 128 |
| 144 - (void)updateWebViewFrame { | 129 - (void)updateWebViewFrame { |
| 145 CGRect webViewFrame = self.bounds; | 130 CGRect webViewFrame = self.bounds; |
| 146 webViewFrame.size.height -= _topContentPadding; | 131 webViewFrame.size.height -= _topContentPadding; |
| 147 webViewFrame.origin.y += _topContentPadding; | 132 webViewFrame.origin.y += _topContentPadding; |
| 148 | 133 |
| 149 self.webView.frame = webViewFrame; | 134 self.webView.frame = webViewFrame; |
| 150 } | 135 } |
| 151 | 136 |
| 152 @end | 137 @end |
| OLD | NEW |