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

Side by Side Diff: third_party/WebKit/Source/core/html/ImageDocument.cpp

Issue 2445413003: [Blink] Display images on a dark background (Closed)
Patch Set: Use finish Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageDocument.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 lockCompatibilityMode(); 193 lockCompatibilityMode();
194 UseCounter::count(*this, UseCounter::ImageDocument); 194 UseCounter::count(*this, UseCounter::ImageDocument);
195 if (!isInMainFrame()) 195 if (!isInMainFrame())
196 UseCounter::count(*this, UseCounter::ImageDocumentInFrame); 196 UseCounter::count(*this, UseCounter::ImageDocumentInFrame);
197 } 197 }
198 198
199 DocumentParser* ImageDocument::createParser() { 199 DocumentParser* ImageDocument::createParser() {
200 return ImageDocumentParser::create(this); 200 return ImageDocumentParser::create(this);
201 } 201 }
202 202
203 void ImageDocument::finishedParsing() {
pdr. 2016/10/26 03:59:06 This isn't your fault but I think the call to fini
204 Document::finishedParsing();
205
206 // Images appear on of a checkerboard background rendered via CSS.
207 // This needs to be set when the image is finished loading.
208 if (shouldShrinkToFit()) {
209 StringBuilder imageStyle;
210 imageStyle.append(m_imageElement->getAttribute(styleAttr));
211 imageStyle.append(
212 "background-position: 0px 0px, 8px 8px;"
213 "background-size: 16px 16px;"
214 "background-color: white;"
215 "background-image:"
216 "linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, "
217 "#eee 75%, #eee 100%),"
218 "linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, "
219 "#eee 75%, #eee 100%);");
220 m_imageElement->setAttribute(styleAttr, imageStyle.toAtomicString());
221 }
222 }
223
203 void ImageDocument::createDocumentStructure() { 224 void ImageDocument::createDocumentStructure() {
204 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*this); 225 HTMLHtmlElement* rootElement = HTMLHtmlElement::create(*this);
205 appendChild(rootElement); 226 appendChild(rootElement);
206 rootElement->insertedByParser(); 227 rootElement->insertedByParser();
207 228
208 if (isStopped()) 229 if (isStopped())
209 return; // runScriptsAtDocumentElementAvailable can detach the frame. 230 return; // runScriptsAtDocumentElementAvailable can detach the frame.
210 231
211 HTMLHeadElement* head = HTMLHeadElement::create(*this); 232 HTMLHeadElement* head = HTMLHeadElement::create(*this);
212 HTMLMetaElement* meta = HTMLMetaElement::create(*this); 233 HTMLMetaElement* meta = HTMLMetaElement::create(*this);
213 meta->setAttribute(nameAttr, "viewport"); 234 meta->setAttribute(nameAttr, "viewport");
214 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1"); 235 meta->setAttribute(contentAttr, "width=device-width, minimum-scale=0.1");
215 head->appendChild(meta); 236 head->appendChild(meta);
216 237
217 HTMLBodyElement* body = HTMLBodyElement::create(*this); 238 HTMLBodyElement* body = HTMLBodyElement::create(*this);
218 239
219 if (shouldShrinkToFit()) { 240 if (shouldShrinkToFit()) {
220 // Display the image prominently centered in the frame. 241 // Display the image prominently centered in the frame.
221 body->setAttribute(styleAttr, "margin: 0px;"); 242 body->setAttribute(styleAttr, "margin: 0px; background: #0e0e0e;");
222 243
223 // See w3c example on how to centering an element: 244 // See w3c example on how to centering an element:
224 // https://www.w3.org/Style/Examples/007/center.en.html 245 // https://www.w3.org/Style/Examples/007/center.en.html
225 m_divElement = HTMLDivElement::create(*this); 246 m_divElement = HTMLDivElement::create(*this);
226 m_divElement->setAttribute(styleAttr, 247 m_divElement->setAttribute(styleAttr,
227 "display: flex;" 248 "display: flex;"
228 "flex-direction: column;" 249 "flex-direction: column;"
229 "justify-content: center;" 250 "justify-content: center;"
230 "align-items: center;" 251 "align-items: center;"
231 "min-height: min-content;" 252 "min-height: min-content;"
232 "min-width: min-content;" 253 "min-width: min-content;"
233 "height: 100%;" 254 "height: 100%;"
234 "width: 100%;"); 255 "width: 100%;");
235 HTMLContentElement* content = HTMLContentElement::create(*this); 256 HTMLContentElement* content = HTMLContentElement::create(*this);
236 m_divElement->appendChild(content); 257 m_divElement->appendChild(content);
237 258
238 ShadowRoot& shadowRoot = body->ensureUserAgentShadowRoot(); 259 ShadowRoot& shadowRoot = body->ensureUserAgentShadowRoot();
239 shadowRoot.appendChild(m_divElement); 260 shadowRoot.appendChild(m_divElement);
240 } else { 261 } else {
241 body->setAttribute(styleAttr, "margin: 0px;"); 262 body->setAttribute(styleAttr, "margin: 0px;");
242 } 263 }
243 264
244 willInsertBody(); 265 willInsertBody();
245 266
246 StringBuilder imageStyle; 267 StringBuilder imageStyle;
247 imageStyle.append("-webkit-user-select: none;"); 268 imageStyle.append("-webkit-user-select: none;");
248 if (shouldShrinkToFit() && m_shrinkToFitMode == Viewport) 269 if (shouldShrinkToFit() && m_shrinkToFitMode == Viewport)
249 imageStyle.append("max-width: 100%"); 270 imageStyle.append("max-width: 100%;");
250 m_imageElement = HTMLImageElement::create(*this); 271 m_imageElement = HTMLImageElement::create(*this);
251 m_imageElement->setAttribute(styleAttr, imageStyle.toAtomicString()); 272 m_imageElement->setAttribute(styleAttr, imageStyle.toAtomicString());
252 m_imageElement->setLoadingImageDocument(); 273 m_imageElement->setLoadingImageDocument();
253 m_imageElement->setSrc(url().getString()); 274 m_imageElement->setSrc(url().getString());
254 body->appendChild(m_imageElement.get()); 275 body->appendChild(m_imageElement.get());
255 if (loader() && m_imageElement->cachedImage()) 276 if (loader() && m_imageElement->cachedImage())
256 m_imageElement->cachedImage()->responseReceived(loader()->response(), 277 m_imageElement->cachedImage()->responseReceived(loader()->response(),
257 nullptr); 278 nullptr);
258 279
259 if (shouldShrinkToFit()) { 280 if (shouldShrinkToFit()) {
260 // Add event listeners 281 // Add event listeners
261 EventListener* listener = ImageEventListener::create(this); 282 EventListener* listener = ImageEventListener::create(this);
262 if (LocalDOMWindow* domWindow = this->domWindow()) 283 if (LocalDOMWindow* domWindow = this->domWindow())
263 domWindow->addEventListener("resize", listener, false); 284 domWindow->addEventListener(EventTypeNames::resize, listener, false);
264 if (m_shrinkToFitMode == Desktop) 285 if (m_shrinkToFitMode == Desktop)
265 m_imageElement->addEventListener("click", listener, false); 286 m_imageElement->addEventListener(EventTypeNames::click, listener, false);
266 } 287 }
267 288
268 rootElement->appendChild(head); 289 rootElement->appendChild(head);
269 rootElement->appendChild(body); 290 rootElement->appendChild(body);
270 } 291 }
271 292
272 float ImageDocument::scale() const { 293 float ImageDocument::scale() const {
273 DCHECK_EQ(m_shrinkToFitMode, Desktop); 294 DCHECK_EQ(m_shrinkToFitMode, Desktop);
274 if (!m_imageElement || m_imageElement->document() != this) 295 if (!m_imageElement || m_imageElement->document() != this)
275 return 1.0f; 296 return 1.0f;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 520 }
500 521
501 bool ImageEventListener::operator==(const EventListener& listener) const { 522 bool ImageEventListener::operator==(const EventListener& listener) const {
502 if (const ImageEventListener* imageEventListener = 523 if (const ImageEventListener* imageEventListener =
503 ImageEventListener::cast(&listener)) 524 ImageEventListener::cast(&listener))
504 return m_doc == imageEventListener->m_doc; 525 return m_doc == imageEventListener->m_doc;
505 return false; 526 return false;
506 } 527 }
507 528
508 } // namespace blink 529 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/ImageDocument.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698