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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXLayoutObject.cpp

Issue 2522543004: Add support for retrieving image thumbnails as part of the accessibility tree. (Closed)
Patch Set: Fix test failure and add automation apitest Created 4 years 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
OLDNEW
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
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
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)
aboxhall 2016/11/22 19:06:31 It would be neat at some point if we could render
dmazzoni 2016/11/22 22:00:13 True. Not sure if it'd make sense to render them i
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|.
889 float xScale = maxSize.width() ? maxSize.width() * 1.0 / image->width() : 1.0;
890 float yScale =
891 maxSize.height() ? maxSize.height() * 1.0 / image->height() : 1.0;
892 float scale = std::min(xScale, yScale);
893 if (scale >= 1.0)
aboxhall 2016/11/22 19:06:31 Does this mean you can't scale the image up? I can
dmazzoni 2016/11/22 22:00:13 Yes, that's how I've designed it. Doesn't the comm
aboxhall 2016/11/22 22:04:51 I mean you can't pass something larger than the si
dmazzoni 2016/11/22 22:27:03 Clarified in comment.
894 scale = 1.0;
895 int width = std::round(image->width() * scale);
896 int height = std::round(image->height() * scale);
897
898 // Draw the scaled image into a bitmap in native format.
899 SkBitmap bitmap;
900 bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType));
901 SkCanvas canvas(bitmap);
902 canvas.clear(SK_ColorTRANSPARENT);
903 canvas.drawImageRect(image, SkRect::MakeIWH(width, height), nullptr);
904
905 // Copy the bits into a buffer in RGBA_8888 unpremultiplied format
906 // for encoding.
907 SkImageInfo info = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType,
908 kUnpremul_SkAlphaType);
909 size_t rowBytes = info.minRowBytes();
910 Vector<char> pixelStorage(info.getSafeSize(rowBytes));
911 SkPixmap pixmap(info, pixelStorage.data(), rowBytes);
912 if (!SkImage::MakeFromBitmap(bitmap)->readPixels(pixmap, 0, 0))
913 return String();
914
915 // Encode as a PNG and return as a data url.
916 String dataUrl =
917 ImageDataBuffer(
918 IntSize(width, height),
919 reinterpret_cast<const unsigned char*>(pixelStorage.data()))
920 .toDataURL("image/png", 1.0);
921 return dataUrl;
922 }
923
857 String AXLayoutObject::text() const { 924 String AXLayoutObject::text() const {
858 if (isPasswordFieldAndShouldHideValue()) { 925 if (isPasswordFieldAndShouldHideValue()) {
859 if (!getLayoutObject()) 926 if (!getLayoutObject())
860 return String(); 927 return String();
861 928
862 const ComputedStyle* style = getLayoutObject()->style(); 929 const ComputedStyle* style = getLayoutObject()->style();
863 if (!style) 930 if (!style)
864 return String(); 931 return String();
865 932
866 unsigned unmaskedTextLength = AXNodeObject::text().length(); 933 unsigned unmaskedTextLength = AXNodeObject::text().length();
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2402 2469
2403 bool AXLayoutObject::elementAttributeValue( 2470 bool AXLayoutObject::elementAttributeValue(
2404 const QualifiedName& attributeName) const { 2471 const QualifiedName& attributeName) const {
2405 if (!m_layoutObject) 2472 if (!m_layoutObject)
2406 return false; 2473 return false;
2407 2474
2408 return equalIgnoringCase(getAttribute(attributeName), "true"); 2475 return equalIgnoringCase(getAttribute(attributeName), "true");
2409 } 2476 }
2410 2477
2411 } // namespace blink 2478 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698