Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / testing / Internals.mm
index 1b9921c..b2404e2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "Internals.h"
+#import "config.h"
+#import "Internals.h"
 
-#include "DOMURL.h"
-#include "Document.h"
-#include "Editor.h"
-#include "EditorClient.h"
-#include "Frame.h"
+#import "DOMURL.h"
+#import "DictionaryLookup.h"
+#import "Document.h"
+#import "EventHandler.h"
+#import "HitTestResult.h"
+#import "Range.h"
+#import <wtf/SoftLinking.h>
+#import <wtf/cocoa/NSURLExtras.h>
+
+#if PLATFORM(IOS_FAMILY)
+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK(UIKit, UIAccessibilityIsReduceMotionEnabled, BOOL, (void), ())
+#endif
 
 namespace WebCore {
 
 String Internals::userVisibleString(const DOMURL& url)
 {
-    return contextDocument()->frame()->editor().client()->userVisibleString(url.href());
+    return WTF::userVisibleString(url.href());
+}
+
+bool Internals::userPrefersReducedMotion() const
+{
+#if PLATFORM(IOS_FAMILY)
+    return UIAccessibilityIsReduceMotionEnabled();
+#else
+    return [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion];
+#endif
 }
 
+#if PLATFORM(MAC)
+
+ExceptionOr<RefPtr<Range>> Internals::rangeForDictionaryLookupAtLocation(int x, int y)
+{
+    auto* document = contextDocument();
+    if (!document || !document->frame())
+        return Exception { InvalidAccessError };
+
+    document->updateLayoutIgnorePendingStylesheets();
+
+    HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
+    RefPtr<Range> range;
+    std::tie(range, std::ignore) = DictionaryLookup::rangeAtHitTestResult(result);
+    return WTFMove(range);
+}
+
+#endif
+
 }