| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "core/dom/shadow/ShadowRoot.h" | 36 #include "core/dom/shadow/ShadowRoot.h" |
| 37 #include "core/editing/EditingUtilities.h" | 37 #include "core/editing/EditingUtilities.h" |
| 38 #include "core/editing/FrameSelection.h" | 38 #include "core/editing/FrameSelection.h" |
| 39 #include "core/editing/RenderedPosition.h" | 39 #include "core/editing/RenderedPosition.h" |
| 40 #include "core/editing/TextAffinity.h" | 40 #include "core/editing/TextAffinity.h" |
| 41 #include "core/editing/VisibleUnits.h" | 41 #include "core/editing/VisibleUnits.h" |
| 42 #include "core/editing/iterators/CharacterIterator.h" | 42 #include "core/editing/iterators/CharacterIterator.h" |
| 43 #include "core/editing/iterators/TextIterator.h" | 43 #include "core/editing/iterators/TextIterator.h" |
| 44 #include "core/frame/FrameOwner.h" | 44 #include "core/frame/FrameOwner.h" |
| 45 #include "core/frame/FrameView.h" | 45 #include "core/frame/FrameView.h" |
| 46 #include "core/frame/ImageBitmap.h" |
| 46 #include "core/frame/LocalFrame.h" | 47 #include "core/frame/LocalFrame.h" |
| 47 #include "core/frame/Settings.h" | 48 #include "core/frame/Settings.h" |
| 49 #include "core/html/HTMLCanvasElement.h" |
| 48 #include "core/html/HTMLFrameOwnerElement.h" | 50 #include "core/html/HTMLFrameOwnerElement.h" |
| 49 #include "core/html/HTMLImageElement.h" | 51 #include "core/html/HTMLImageElement.h" |
| 50 #include "core/html/HTMLInputElement.h" | 52 #include "core/html/HTMLInputElement.h" |
| 51 #include "core/html/HTMLLabelElement.h" | 53 #include "core/html/HTMLLabelElement.h" |
| 52 #include "core/html/HTMLOptionElement.h" | 54 #include "core/html/HTMLOptionElement.h" |
| 53 #include "core/html/HTMLSelectElement.h" | 55 #include "core/html/HTMLSelectElement.h" |
| 54 #include "core/html/HTMLTextAreaElement.h" | 56 #include "core/html/HTMLTextAreaElement.h" |
| 57 #include "core/html/HTMLVideoElement.h" |
| 58 #include "core/html/ImageData.h" |
| 55 #include "core/html/LabelsNodeList.h" | 59 #include "core/html/LabelsNodeList.h" |
| 56 #include "core/html/shadow/ShadowElementNames.h" | 60 #include "core/html/shadow/ShadowElementNames.h" |
| 61 #include "core/imagebitmap/ImageBitmapOptions.h" |
| 57 #include "core/layout/HitTestResult.h" | 62 #include "core/layout/HitTestResult.h" |
| 58 #include "core/layout/LayoutFileUploadControl.h" | 63 #include "core/layout/LayoutFileUploadControl.h" |
| 59 #include "core/layout/LayoutHTMLCanvas.h" | 64 #include "core/layout/LayoutHTMLCanvas.h" |
| 60 #include "core/layout/LayoutImage.h" | 65 #include "core/layout/LayoutImage.h" |
| 61 #include "core/layout/LayoutInline.h" | 66 #include "core/layout/LayoutInline.h" |
| 62 #include "core/layout/LayoutListMarker.h" | 67 #include "core/layout/LayoutListMarker.h" |
| 63 #include "core/layout/LayoutMenuList.h" | 68 #include "core/layout/LayoutMenuList.h" |
| 64 #include "core/layout/LayoutTextControl.h" | 69 #include "core/layout/LayoutTextControl.h" |
| 65 #include "core/layout/LayoutView.h" | 70 #include "core/layout/LayoutView.h" |
| 66 #include "core/layout/api/LayoutAPIShim.h" | 71 #include "core/layout/api/LayoutAPIShim.h" |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (!getLayoutObject()) | 852 if (!getLayoutObject()) |
| 848 return AXNodeObject::fontSize(); | 853 return AXNodeObject::fontSize(); |
| 849 | 854 |
| 850 const ComputedStyle* style = getLayoutObject()->style(); | 855 const ComputedStyle* style = getLayoutObject()->style(); |
| 851 if (!style) | 856 if (!style) |
| 852 return AXNodeObject::fontSize(); | 857 return AXNodeObject::fontSize(); |
| 853 | 858 |
| 854 return style->computedFontSize(); | 859 return style->computedFontSize(); |
| 855 } | 860 } |
| 856 | 861 |
| 862 String AXLayoutObject::imageDataUrl(const IntSize& maxSize) const { |
| 863 Node* node = getNode(); |
| 864 if (!node) |
| 865 return String(); |
| 866 |
| 867 ImageBitmapOptions options; |
| 868 ImageBitmap* imageBitmap = nullptr; |
| 869 Document* document = &node->document(); |
| 870 if (isHTMLImageElement(node)) { |
| 871 imageBitmap = ImageBitmap::create(toHTMLImageElement(node), |
| 872 Optional<IntRect>(), document, options); |
| 873 } else if (isHTMLCanvasElement(node)) { |
| 874 imageBitmap = ImageBitmap::create(toHTMLCanvasElement(node), |
| 875 Optional<IntRect>(), options); |
| 876 } else if (isHTMLVideoElement(node)) { |
| 877 imageBitmap = ImageBitmap::create(toHTMLVideoElement(node), |
| 878 Optional<IntRect>(), document, options); |
| 879 } |
| 880 if (!imageBitmap) |
| 881 return String(); |
| 882 |
| 883 sk_sp<SkImage> image = imageBitmap->bitmapImage()->imageForCurrentFrame(); |
| 884 if (!image || image->width() <= 0 || image->height() <= 0) |
| 885 return String(); |
| 886 |
| 887 // Determine the width and height of the output image, using a proportional |
| 888 // scale factor such that it's no larger than |maxSize|, if |maxSize| is not |
| 889 // empty. It only resizes the image to be smaller (if necessary), not |
| 890 // larger. |
| 891 float xScale = maxSize.width() ? maxSize.width() * 1.0 / image->width() : 1.0; |
| 892 float yScale = |
| 893 maxSize.height() ? maxSize.height() * 1.0 / image->height() : 1.0; |
| 894 float scale = std::min(xScale, yScale); |
| 895 if (scale >= 1.0) |
| 896 scale = 1.0; |
| 897 int width = std::round(image->width() * scale); |
| 898 int height = std::round(image->height() * scale); |
| 899 |
| 900 // Draw the scaled image into a bitmap in native format. |
| 901 SkBitmap bitmap; |
| 902 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); |
| 903 SkCanvas canvas(bitmap); |
| 904 canvas.clear(SK_ColorTRANSPARENT); |
| 905 canvas.drawImageRect(image, SkRect::MakeIWH(width, height), nullptr); |
| 906 |
| 907 // Copy the bits into a buffer in RGBA_8888 unpremultiplied format |
| 908 // for encoding. |
| 909 SkImageInfo info = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, |
| 910 kUnpremul_SkAlphaType); |
| 911 size_t rowBytes = info.minRowBytes(); |
| 912 Vector<char> pixelStorage(info.getSafeSize(rowBytes)); |
| 913 SkPixmap pixmap(info, pixelStorage.data(), rowBytes); |
| 914 if (!SkImage::MakeFromBitmap(bitmap)->readPixels(pixmap, 0, 0)) |
| 915 return String(); |
| 916 |
| 917 // Encode as a PNG and return as a data url. |
| 918 String dataUrl = |
| 919 ImageDataBuffer( |
| 920 IntSize(width, height), |
| 921 reinterpret_cast<const unsigned char*>(pixelStorage.data())) |
| 922 .toDataURL("image/png", 1.0); |
| 923 return dataUrl; |
| 924 } |
| 925 |
| 857 String AXLayoutObject::text() const { | 926 String AXLayoutObject::text() const { |
| 858 if (isPasswordFieldAndShouldHideValue()) { | 927 if (isPasswordFieldAndShouldHideValue()) { |
| 859 if (!getLayoutObject()) | 928 if (!getLayoutObject()) |
| 860 return String(); | 929 return String(); |
| 861 | 930 |
| 862 const ComputedStyle* style = getLayoutObject()->style(); | 931 const ComputedStyle* style = getLayoutObject()->style(); |
| 863 if (!style) | 932 if (!style) |
| 864 return String(); | 933 return String(); |
| 865 | 934 |
| 866 unsigned unmaskedTextLength = AXNodeObject::text().length(); | 935 unsigned unmaskedTextLength = AXNodeObject::text().length(); |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2402 | 2471 |
| 2403 bool AXLayoutObject::elementAttributeValue( | 2472 bool AXLayoutObject::elementAttributeValue( |
| 2404 const QualifiedName& attributeName) const { | 2473 const QualifiedName& attributeName) const { |
| 2405 if (!m_layoutObject) | 2474 if (!m_layoutObject) |
| 2406 return false; | 2475 return false; |
| 2407 | 2476 |
| 2408 return equalIgnoringCase(getAttribute(attributeName), "true"); | 2477 return equalIgnoringCase(getAttribute(attributeName), "true"); |
| 2409 } | 2478 } |
| 2410 | 2479 |
| 2411 } // namespace blink | 2480 } // namespace blink |
| OLD | NEW |