diff --git a/.dockerignore b/.dockerignore index 0dee486c38..44e9a55914 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,7 +9,6 @@ nddl/*/libnme* project/all_objs project/obj project/vc*.pdb -project/winrt/shaders/ *.userprefs *.swp .idea/ diff --git a/.gitmodules b/.gitmodules index 393daa81a4..4c845a3f4f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,10 +22,6 @@ path = project/lib/zlib url = https://github.com/madler/zlib shallow = true -[submodule "project/lib/neko"] - path = project/lib/neko - url = https://github.com/HaxeFoundation/neko - shallow = true [submodule "project/lib/png"] path = project/lib/png url = https://github.com/glennrp/libpng @@ -59,14 +55,6 @@ path = project/lib/efsw url = https://github.com/SpartanJ/efsw shallow = true -[submodule "project/lib/vpx"] - path = project/lib/vpx - url = https://github.com/webmproject/libvpx - shallow = true -[submodule "project/lib/webm"] - path = project/lib/webm - url = https://github.com/webmproject/libwebm - shallow = true [submodule "project/lib/mbedtls"] path = project/lib/mbedtls url = https://github.com/Mbed-TLS/mbedtls diff --git a/include.xml b/include.xml index 28ed79d16c..46bd701e45 100644 --- a/include.xml +++ b/include.xml @@ -7,7 +7,7 @@ - + @@ -25,7 +25,6 @@ - @@ -33,9 +32,6 @@ - - - @@ -77,7 +73,7 @@
- +
diff --git a/project/Build.xml b/project/Build.xml index 080273bf5a..b8201db9f1 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -12,35 +12,31 @@ - - + + - - - + - - + + - + + - - @@ -92,15 +88,6 @@
-
- - - - - - -
-
@@ -158,15 +145,6 @@
-
- - - - - - -
-
@@ -202,7 +180,7 @@
- + @@ -232,14 +210,6 @@
- - - - - - - -
@@ -262,7 +232,6 @@ - @@ -299,7 +268,6 @@ - @@ -332,20 +300,9 @@ - - - - - - - - - - - @@ -353,17 +310,15 @@ - - - + @@ -373,19 +328,16 @@ - - - @@ -393,51 +345,39 @@ - -
- -
- - - - - + + + + + + + + + + + + - + - - - - - - - - - - - - - - - + -
@@ -446,9 +386,6 @@ - - - @@ -456,10 +393,6 @@
- @@ -483,9 +416,6 @@ - - - diff --git a/project/include/hx/CFFIExt.h b/project/include/hx/CFFIExt.h deleted file mode 100644 index 43c0b7d04b..0000000000 --- a/project/include/hx/CFFIExt.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef HX_CFFIEXT_INCLUDED -#define HX_CFFIEXT_INCLUDED - -#include - -#if defined(STATIC_LINK) && defined(IMPLEMENT_CFFI_EXT) -void *LoadFunc(const char *inName) { return 0; } -#else -extern void *LoadFunc(const char *inName); -#endif - -#ifdef IMPLEMENT_CFFI_EXT -#define DEFFUNC_EXT(name,ret,def_args,call_args) \ - typedef ret (*FUNC_##name)def_args; \ - FUNC_##name IMPL_##name = NULL; \ - extern FUNC_##name EXT_##name; \ - bool LOADED_##name = false; \ - bool HAS_##name () \ - { \ - if (!LOADED_##name) \ - { \ - IMPL_##name = (FUNC_##name)LoadFunc(#name); \ - LOADED_##name = true; \ - } \ - return IMPL_##name != NULL; \ - } \ - ret REAL_##name def_args \ - { \ - if (!HAS_##name()) \ - { \ - fprintf(stderr,"Could not find external function:" #name " \n"); \ - abort(); \ - } \ - EXT_##name = IMPL_##name; \ - return IMPL_##name call_args; \ - } \ - FUNC_##name EXT_##name = REAL_##name; -#else -#define DEFFUNC_EXT(name,ret,def_args,call_args) \ -typedef ret (*FUNC_##name)def_args; \ -extern bool HAS_##name (); \ -extern FUNC_##name EXT_##name; -#endif - -#define DEFFUNC_EXT_0(ret,name) DEFFUNC_EXT(name,ret, (), ()) -#define DEFFUNC_EXT_1(ret,name,t1) DEFFUNC_EXT(name,ret, (t1 a1), (a1)) -#define DEFFUNC_EXT_2(ret,name,t1,t2) DEFFUNC_EXT(name,ret, (t1 a1, t2 a2), (a1,a2)) -#define DEFFUNC_EXT_3(ret,name,t1,t2,t3) DEFFUNC_EXT(name,ret, (t1 a1, t2 a2, t3 a3), (a1,a2,a3)) -#define DEFFUNC_EXT_4(ret,name,t1,t2,t3,t4) DEFFUNC_EXT(name,ret, (t1 a1, t2 a2, t3 a3, t4 a4), (a1,a2,a3,a4)) -#define DEFFUNC_EXT_5(ret,name,t1,t2,t3,t4,t5) DEFFUNC_EXT(name,ret, (t1 a1, t2 a2, t3 a3, t4 a4,t5 a5), (a1,a2,a3,a4,a5)) - -DEFFUNC_EXT_1(value,pin_buffer,buffer); -DEFFUNC_EXT_1(void,unpin_buffer,value); -DEFFUNC_EXT_2(value,alloc_array_type,int,hxValueType); - -static value alloc_array_type_wrap(int size, hxValueType type) -{ - return HAS_alloc_array_type() ? EXT_alloc_array_type(size, type) : alloc_array (size); -} - -#endif \ No newline at end of file diff --git a/project/include/media/AudioBuffer.h b/project/include/media/AudioBuffer.h index 3a60eb9023..94dac9c443 100644 --- a/project/include/media/AudioBuffer.h +++ b/project/include/media/AudioBuffer.h @@ -5,26 +5,6 @@ #include #include -#ifdef ANDROID -#include -#endif - - -#ifdef ANDROID -#define LOG_SOUND(args,...) __android_log_print(ANDROID_LOG_INFO, "Lime", args, ##__VA_ARGS__) -#else -#ifdef IPHONE -//#define LOG_SOUND(args,...) printf(args, ##__VA_ARGS__) -#define LOG_SOUND(args...) { } -#elif defined(TIZEN) -#include -#define LOG_SOUND(args,...) AppLog(args, ##__VA_ARGS__) -#else -#define LOG_SOUND(args,...) printf(args, ##__VA_ARGS__) -#endif -#endif -//#define LOG_SOUND(args...) { } - namespace lime { diff --git a/project/include/system/System.h b/project/include/system/System.h index c5d6d0ceed..928486d4a8 100644 --- a/project/include/system/System.h +++ b/project/include/system/System.h @@ -1,6 +1,7 @@ #ifndef LIME_SYSTEM_SYSTEM_H #define LIME_SYSTEM_SYSTEM_H + #include #include #include @@ -45,18 +46,12 @@ namespace lime { static std::wstring* GetPlatformName (); static std::wstring* GetPlatformVersion (); static double GetTimer (); - #if defined(HX_WINDOWS) && !defined (HX_WINRT) - static int GetWindowsConsoleMode (int handleType); - #endif static void OpenFile (const char* path); static void OpenURL (const char* url, const char* target); static bool SetAllowScreenTimeout (bool allow); static int GetDisplayOrientation (int displayIndex); static std::wstring* GetHint (const char* key); static void SetHint (const char* key, const char* value); - #if defined(HX_WINDOWS) && !defined (HX_WINRT) - static bool SetWindowsConsoleMode (int handleType, int mode); - #endif private: @@ -92,278 +87,4 @@ namespace lime { } -#ifndef HX_WINDOWS -#include -#else - - -// ISO C9x compliant stdint.h for Microsoft Visual Studio -// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 -// -// Copyright (c) 2006-2013 Alexander Chemeris -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of the product nor the names of its contributors may -// be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO -// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef _MSC_VER // [ -#error "Use this header only with Microsoft Visual C++ compilers!" -#endif // _MSC_VER ] - -#ifndef _MSC_STDINT_H_ // [ -#define _MSC_STDINT_H_ - -#if _MSC_VER > 1000 -#pragma once -#endif - -#if _MSC_VER >= 1600 // [ -#include -#else // ] _MSC_VER >= 1600 [ - -#include - -// For Visual Studio 6 in C++ mode and for many Visual Studio versions when -// compiling for ARM we should wrap include with 'extern "C++" {}' -// or compiler give many errors like this: -// error C2733: second C linkage of overloaded function 'wmemchr' not allowed -#ifdef __cplusplus -extern "C" { -#endif -# include -#ifdef __cplusplus -} -#endif - -// Define _W64 macros to mark types changing their size, like intptr_t. -#ifndef _W64 -# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 -# define _W64 __w64 -# else -# define _W64 -# endif -#endif - - -// 7.18.1 Integer types - -// 7.18.1.1 Exact-width integer types - -// Visual Studio 6 and Embedded Visual C++ 4 doesn't -// realize that, e.g. char has the same size as __int8 -// so we give up on __intX for them. -#if (_MSC_VER < 1300) - typedef signed char int8_t; - typedef signed short int16_t; - typedef signed int int32_t; - typedef unsigned char uint8_t; - typedef unsigned short uint16_t; - typedef unsigned int uint32_t; -#else - typedef signed __int8 int8_t; - typedef signed __int16 int16_t; - typedef signed __int32 int32_t; - typedef unsigned __int8 uint8_t; - typedef unsigned __int16 uint16_t; - typedef unsigned __int32 uint32_t; -#endif -typedef signed __int64 int64_t; -typedef unsigned __int64 uint64_t; - - -// 7.18.1.2 Minimum-width integer types -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -// 7.18.1.3 Fastest minimum-width integer types -typedef int8_t int_fast8_t; -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef int64_t int_fast64_t; -typedef uint8_t uint_fast8_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; -typedef uint64_t uint_fast64_t; - -// 7.18.1.4 Integer types capable of holding object pointers -#ifdef _WIN64 // [ - typedef signed __int64 intptr_t; - typedef unsigned __int64 uintptr_t; -#else // _WIN64 ][ - typedef _W64 signed int intptr_t; - typedef _W64 unsigned int uintptr_t; -#endif // _WIN64 ] - -// 7.18.1.5 Greatest-width integer types -typedef int64_t intmax_t; -typedef uint64_t uintmax_t; - - -// 7.18.2 Limits of specified-width integer types - -#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 - -// 7.18.2.1 Limits of exact-width integer types -#define INT8_MIN ((int8_t)_I8_MIN) -#define INT8_MAX _I8_MAX -#define INT16_MIN ((int16_t)_I16_MIN) -#define INT16_MAX _I16_MAX -#define INT32_MIN ((int32_t)_I32_MIN) -#define INT32_MAX _I32_MAX -#define INT64_MIN ((int64_t)_I64_MIN) -#define INT64_MAX _I64_MAX -#define UINT8_MAX _UI8_MAX -#define UINT16_MAX _UI16_MAX -#define UINT32_MAX _UI32_MAX -#define UINT64_MAX _UI64_MAX - -// 7.18.2.2 Limits of minimum-width integer types -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST64_MIN INT64_MIN -#define INT_LEAST64_MAX INT64_MAX -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -// 7.18.2.3 Limits of fastest minimum-width integer types -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MIN INT32_MIN -#define INT_FAST32_MAX INT32_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX -#define UINT_FAST64_MAX UINT64_MAX - -// 7.18.2.4 Limits of integer types capable of holding object pointers -#ifdef _WIN64 // [ -# define INTPTR_MIN INT64_MIN -# define INTPTR_MAX INT64_MAX -# define UINTPTR_MAX UINT64_MAX -#else // _WIN64 ][ -# define INTPTR_MIN INT32_MIN -# define INTPTR_MAX INT32_MAX -# define UINTPTR_MAX UINT32_MAX -#endif // _WIN64 ] - -// 7.18.2.5 Limits of greatest-width integer types -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -// 7.18.3 Limits of other integer types - -#ifdef _WIN64 // [ -# define PTRDIFF_MIN _I64_MIN -# define PTRDIFF_MAX _I64_MAX -#else // _WIN64 ][ -# define PTRDIFF_MIN _I32_MIN -# define PTRDIFF_MAX _I32_MAX -#endif // _WIN64 ] - -#define SIG_ATOMIC_MIN INT_MIN -#define SIG_ATOMIC_MAX INT_MAX - -#ifndef SIZE_MAX // [ -# ifdef _WIN64 // [ -# define SIZE_MAX _UI64_MAX -# else // _WIN64 ][ -# define SIZE_MAX _UI32_MAX -# endif // _WIN64 ] -#endif // SIZE_MAX ] - -// WCHAR_MIN and WCHAR_MAX are also defined in -#ifndef WCHAR_MIN // [ -# define WCHAR_MIN 0 -#endif // WCHAR_MIN ] -#ifndef WCHAR_MAX // [ -# define WCHAR_MAX _UI16_MAX -#endif // WCHAR_MAX ] - -#define WINT_MIN 0 -#define WINT_MAX _UI16_MAX - -#endif // __STDC_LIMIT_MACROS ] - - -// 7.18.4 Limits of other integer types - -#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 - -// 7.18.4.1 Macros for minimum-width integer constants - -#define INT8_C(val) val##i8 -#define INT16_C(val) val##i16 -#define INT32_C(val) val##i32 -#define INT64_C(val) val##i64 - -#define UINT8_C(val) val##ui8 -#define UINT16_C(val) val##ui16 -#define UINT32_C(val) val##ui32 -#define UINT64_C(val) val##ui64 - -// 7.18.4.2 Macros for greatest-width integer constants -// These #ifndef's are needed to prevent collisions with . -// Check out Issue 9 for the details. -#ifndef INTMAX_C // [ -# define INTMAX_C INT64_C -#endif // INTMAX_C ] -#ifndef UINTMAX_C // [ -# define UINTMAX_C UINT64_C -#endif // UINTMAX_C ] - -#endif // __STDC_CONSTANT_MACROS ] - -#endif // _MSC_VER >= 1600 ] - -#endif // _MSC_STDINT_H_ ] -#endif - - -#if defined(ANDROID) && !defined(HXCPP_CLANG) - -std::size_t _mbsrtowcs(wchar_t * ws, const char **src, std::size_t wn, std::mbstate_t *st); - -#endif - - -#endif +#endif \ No newline at end of file diff --git a/project/include/vm/NekoVM.h b/project/include/vm/NekoVM.h deleted file mode 100644 index f569dd9bd9..0000000000 --- a/project/include/vm/NekoVM.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LIME_VM_NEKOVM_H -#define LIME_VM_NEKOVM_H - - -namespace lime { - - - class NekoVM { - - public: - - static void Execute (const char *module); - - }; - - -} - - -#endif \ No newline at end of file diff --git a/project/lib/neko b/project/lib/neko deleted file mode 160000 index ff67a696a7..0000000000 --- a/project/lib/neko +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ff67a696a718cba0a6bc0ec583e355272b4a5923 diff --git a/project/lib/vpx b/project/lib/vpx deleted file mode 160000 index 626ff35955..0000000000 --- a/project/lib/vpx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 626ff35955c2c35b806b3e0ecf551a1a8611cdbf diff --git a/project/lib/vpx-files.xml b/project/lib/vpx-files.xml deleted file mode 100644 index 014a548d97..0000000000 --- a/project/lib/vpx-files.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/lib/webm b/project/lib/webm deleted file mode 160000 index 82a1d2330e..0000000000 --- a/project/lib/webm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82a1d2330e113a14e545d806eb5419f09374255f diff --git a/project/lib/webm-files.xml b/project/lib/webm-files.xml deleted file mode 100644 index 4ca647ab3b..0000000000 --- a/project/lib/webm-files.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index b30429013e..c708633fcb 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #ifdef HX_WINDOWS #include @@ -2603,15 +2602,6 @@ namespace lime { } - void lime_neko_execute (HxString module) { - - #ifdef LIME_NEKO - NekoVM::Execute (module.c_str ()); - #endif - - } - - value lime_png_decode_bytes (value data, bool decodeData, value buffer) { ImageBuffer imageBuffer (buffer); @@ -3037,28 +3027,6 @@ namespace lime { } - int lime_system_get_windows_console_mode (int handleType) { - - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - return System::GetWindowsConsoleMode (handleType); - #else - return 0; - #endif - - } - - - HL_PRIM int HL_NAME(hl_system_get_windows_console_mode) (int handleType) { - - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - return System::GetWindowsConsoleMode (handleType); - #else - return 0; - #endif - - } - - void lime_system_open_file (HxString path) { System::OpenFile (path.c_str ()); @@ -3161,28 +3129,6 @@ namespace lime { } - bool lime_system_set_windows_console_mode (int handleType, int mode) { - - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - return System::SetWindowsConsoleMode (handleType, mode); - #else - return false; - #endif - - } - - - HL_PRIM bool HL_NAME(hl_system_set_windows_console_mode) (int handleType, int mode) { - - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - return System::SetWindowsConsoleMode (handleType, mode); - #else - return false; - #endif - - } - - void lime_text_event_manager_register (value callback, value eventObject) { TextEvent::callback = new ValuePointer (callback); @@ -4156,7 +4102,6 @@ namespace lime { DEFINE_PRIME2 (lime_lzma_compress); DEFINE_PRIME2 (lime_lzma_decompress); DEFINE_PRIME2v (lime_mouse_event_manager_register); - DEFINE_PRIME1v (lime_neko_execute); DEFINE_PRIME3 (lime_png_decode_bytes); DEFINE_PRIME3 (lime_png_decode_file); DEFINE_PRIME2v (lime_render_event_manager_register); @@ -4173,14 +4118,12 @@ namespace lime { DEFINE_PRIME0 (lime_system_get_platform_name); DEFINE_PRIME0 (lime_system_get_platform_version); DEFINE_PRIME0 (lime_system_get_timer); - DEFINE_PRIME1 (lime_system_get_windows_console_mode); DEFINE_PRIME1v (lime_system_open_file); DEFINE_PRIME2v (lime_system_open_url); DEFINE_PRIME1 (lime_system_set_allow_screen_timeout); DEFINE_PRIME1 (lime_system_get_display_orientation); DEFINE_PRIME1 (lime_system_get_hint); DEFINE_PRIME2v (lime_system_set_hint); - DEFINE_PRIME2 (lime_system_set_windows_console_mode); DEFINE_PRIME2v (lime_text_event_manager_register); DEFINE_PRIME2v (lime_touch_event_manager_register); DEFINE_PRIME5 (lime_window_alert); @@ -4350,7 +4293,6 @@ namespace lime { DEFINE_HL_PRIM (_TBYTES, hl_lzma_compress, _TBYTES _TBYTES); DEFINE_HL_PRIM (_TBYTES, hl_lzma_decompress, _TBYTES _TBYTES); DEFINE_HL_PRIM (_VOID, hl_mouse_event_manager_register, _FUN (_VOID, _NO_ARG) _TMOUSE_EVENT); - // DEFINE_PRIME1v (lime_neko_execute); DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_png_decode_bytes, _TBYTES _BOOL _TIMAGEBUFFER); DEFINE_HL_PRIM (_TIMAGEBUFFER, hl_png_decode_file, _STRING _BOOL _TIMAGEBUFFER); DEFINE_HL_PRIM (_VOID, hl_render_event_manager_register, _FUN (_VOID, _NO_ARG) _TRENDER_EVENT); @@ -4367,14 +4309,12 @@ namespace lime { DEFINE_HL_PRIM (_BYTES, hl_system_get_platform_name, _NO_ARG); DEFINE_HL_PRIM (_BYTES, hl_system_get_platform_version, _NO_ARG); DEFINE_HL_PRIM (_F64, hl_system_get_timer, _NO_ARG); - DEFINE_HL_PRIM (_I32, hl_system_get_windows_console_mode, _I32); DEFINE_HL_PRIM (_VOID, hl_system_open_file, _STRING); DEFINE_HL_PRIM (_VOID, hl_system_open_url, _STRING _STRING); DEFINE_HL_PRIM (_BOOL, hl_system_set_allow_screen_timeout, _BOOL); DEFINE_HL_PRIM (_I32, hl_system_get_display_orientation, _I32); DEFINE_HL_PRIM (_BYTES, hl_system_get_hint, _STRING); DEFINE_HL_PRIM (_VOID, hl_system_set_hint, _STRING _STRING); - DEFINE_HL_PRIM (_BOOL, hl_system_set_windows_console_mode, _I32 _I32); DEFINE_HL_PRIM (_VOID, hl_text_event_manager_register, _FUN (_VOID, _NO_ARG) _TTEXT_EVENT); DEFINE_HL_PRIM (_VOID, hl_touch_event_manager_register, _FUN (_VOID, _NO_ARG) _TTOUCH_EVENT); DEFINE_HL_PRIM (_I32, hl_window_alert, _TCFFIPOINTER _I32 _STRING _STRING _ARR); diff --git a/project/src/backend/sdl/SDLSystem.cpp b/project/src/backend/sdl/SDLSystem.cpp index 5fde7575c1..ef654c8cf1 100644 --- a/project/src/backend/sdl/SDLSystem.cpp +++ b/project/src/backend/sdl/SDLSystem.cpp @@ -150,12 +150,7 @@ namespace lime { case DESKTOP: { - #if defined (HX_WINRT) - - Windows::Storage::StorageFolder^ folder = Windows::Storage::KnownFolders::HomeGroup; - result = new std::wstring (folder->Path->Data ()); - - #elif defined (HX_WINDOWS) + #if defined (HX_WINDOWS) char folderPath[MAX_PATH] = ""; SHGetFolderPath (NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, folderPath); @@ -187,12 +182,7 @@ namespace lime { case DOCUMENTS: { - #if defined (HX_WINRT) - - Windows::Storage::StorageFolder^ folder = Windows::Storage::KnownFolders::DocumentsLibrary; - result = new std::wstring (folder->Path->Data ()); - - #elif defined (HX_WINDOWS) + #if defined (HX_WINDOWS) char folderPath[MAX_PATH] = ""; SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, folderPath); @@ -226,11 +216,7 @@ namespace lime { case FONTS: { - #if defined (HX_WINRT) - - // TODO - - #elif defined (HX_WINDOWS) + #if defined (HX_WINDOWS) char folderPath[MAX_PATH] = ""; SHGetFolderPath (NULL, CSIDL_FONTS, NULL, SHGFP_TYPE_CURRENT, folderPath); @@ -250,10 +236,6 @@ namespace lime { result = new std::wstring (L"/system/fonts"); - #elif defined (BLACKBERRY) - - result = new std::wstring (L"/usr/fonts/font_repository/monotype"); - #else result = new std::wstring (L"/usr/share/fonts/truetype"); @@ -265,12 +247,7 @@ namespace lime { case USER: { - #if defined (HX_WINRT) - - Windows::Storage::StorageFolder^ folder = Windows::Storage::ApplicationData::Current->RoamingFolder; - result = new std::wstring (folder->Path->Data ()); - - #elif defined (HX_WINDOWS) + #if defined (HX_WINDOWS) char folderPath[MAX_PATH] = ""; SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, folderPath); diff --git a/project/src/hx/CFFIExt.cpp b/project/src/hx/CFFIExt.cpp deleted file mode 100644 index a55255339f..0000000000 --- a/project/src/hx/CFFIExt.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#define IMPLEMENT_CFFI_EXT - -#include diff --git a/project/src/media/containers/OGG.cpp b/project/src/media/containers/OGG.cpp index 4dc363e91c..6701d8d9b7 100644 --- a/project/src/media/containers/OGG.cpp +++ b/project/src/media/containers/OGG.cpp @@ -43,7 +43,6 @@ namespace lime { if (pInfo == NULL) { - //LOG_SOUND("FAILED TO READ OGG SOUND INFO, IS THIS EVEN AN OGG FILE?\n"); ov_clear (oggFile); delete oggFile; diff --git a/project/src/media/containers/WAV.cpp b/project/src/media/containers/WAV.cpp index 1f88d03344..bbd0b2fa4e 100644 --- a/project/src/media/containers/WAV.cpp +++ b/project/src/media/containers/WAV.cpp @@ -80,7 +80,6 @@ namespace lime { if (result != 1) { - LOG_SOUND ("Invalid Wave Format!\n"); lime::fclose (file); return false; @@ -107,7 +106,6 @@ namespace lime { if (result != 1) { - LOG_SOUND ("Invalid Wav Data Header!\n"); lime::fclose (file); return false; @@ -129,7 +127,6 @@ namespace lime { if (!lime::fread (audioBuffer->data->buffer->b, wave_data.subChunkSize, 1, file)) { - LOG_SOUND ("error loading WAVE data into struct!\n"); lime::fclose (file); return false; @@ -164,7 +161,6 @@ namespace lime { if (wave_format.subChunkID[0] != 'f' || wave_format.subChunkID[1] != 'm' || wave_format.subChunkID[2] != 't' || wave_format.subChunkID[3] != ' ') { - LOG_SOUND ("Invalid Wave Format!\n"); return false; } @@ -181,7 +177,6 @@ namespace lime { if (wave_data.subChunkID[0] != 'd' || wave_data.subChunkID[1] != 'a' || wave_data.subChunkID[2] != 't' || wave_data.subChunkID[3] != 'a') { - LOG_SOUND ("Invalid Wav Data Header!\n"); return false; } diff --git a/project/src/system/System.cpp b/project/src/system/System.cpp index b8691178d3..c2a0837744 100644 --- a/project/src/system/System.cpp +++ b/project/src/system/System.cpp @@ -66,7 +66,7 @@ namespace lime { } - #if defined (HX_WINDOWS) && !defined (HX_WINRT) + #if defined (HX_WINDOWS) std::wstring* GetWMIValue (BSTR query, BSTR field) { HRESULT hres = 0; @@ -163,7 +163,7 @@ namespace lime { std::wstring* System::GetDeviceModel () { - #if defined (HX_WINDOWS) && !defined (HX_WINRT) + #if defined (HX_WINDOWS) return GetWMIValue (_bstr_t(L"SELECT * FROM Win32_ComputerSystemProduct"), _bstr_t(L"Version")); #endif @@ -174,7 +174,7 @@ namespace lime { std::wstring* System::GetDeviceVendor () { - #if defined (HX_WINDOWS) && !defined (HX_WINRT) + #if defined (HX_WINDOWS) return GetWMIValue (_bstr_t(L"SELECT * FROM Win32_ComputerSystemProduct"), _bstr_t(L"Vendor")); #endif @@ -185,7 +185,7 @@ namespace lime { std::wstring* System::GetPlatformLabel () { - #if defined (HX_WINDOWS) && !defined (HX_WINRT) + #if defined (HX_WINDOWS) return GetWMIValue (_bstr_t(L"SELECT * FROM Win32_OperatingSystem"), _bstr_t(L"Caption")); #endif @@ -203,7 +203,7 @@ namespace lime { std::wstring* System::GetPlatformVersion () { - #if defined (HX_WINDOWS) && !defined (HX_WINRT) + #if defined (HX_WINDOWS) return GetWMIValue (_bstr_t(L"SELECT * FROM Win32_OperatingSystem"), _bstr_t(L"Version")); #endif @@ -212,203 +212,4 @@ namespace lime { } - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - int System::GetWindowsConsoleMode (int handleType) { - - HANDLE handle = GetStdHandle ((DWORD)handleType); - DWORD mode = 0; - - if (handle) { - - bool result = GetConsoleMode (handle, &mode); - - } - - return mode; - - } - #endif - - - #if defined (HX_WINDOWS) && !defined (HX_WINRT) - bool System::SetWindowsConsoleMode (int handleType, int mode) { - - HANDLE handle = GetStdHandle ((DWORD)handleType); - - if (handle) { - - return SetConsoleMode (handle, (DWORD)mode); - - } - - return false; - - } - #endif - - -} - - -#ifdef HX_LINUX - -// Improve compatibility with old glibc - -#define __fdelt_chk __fdelt_chk_local -#include -#undef __fdelt_chk - -long int __fdelt_chk (long int d) { - - if (d >= FD_SETSIZE) { - - //printf("Select - bad fd.\n"); - return 0; - - } - - return d / __NFDBITS; - } - -#endif - - -#if defined(ANDROID) && !defined(HXCPP_CLANG) - -#include -#include -#include - -/* -* This code was written by Rich Felker in 2010; no copyright is claimed. -* This code is in the public domain. Attribution is appreciated but -* unnecessary. -*/ - -#define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7) - -#define R(a,b) ((uint32_t)((a==0x80 ? 0x40-b : -a) << 23)) - -#define C(x) ( x<2 ? -1 : ( R(0x80,0xc0) | x ) ) -#define D(x) C((x+16)) -#define E(x) ( ( x==0 ? R(0xa0,0xc0) : \ - x==0xd ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | x ) -#define F(x) ( ( x>=5 ? 0 : \ - x==0 ? R(0x90,0xc0) : \ - x==4 ? R(0x80,0xa0) : \ - R(0x80,0xc0) ) \ - | ( R(0x80,0xc0) >> 6 ) \ - | ( R(0x80,0xc0) >> 12 ) \ - | x ) - -#define SA 0xc2u -#define SB 0xf4u - -const uint32_t bittab[] = { - C(0x2),C(0x3),C(0x4),C(0x5),C(0x6),C(0x7), - C(0x8),C(0x9),C(0xa),C(0xb),C(0xc),C(0xd),C(0xe),C(0xf), - D(0x0),D(0x1),D(0x2),D(0x3),D(0x4),D(0x5),D(0x6),D(0x7), - D(0x8),D(0x9),D(0xa),D(0xb),D(0xc),D(0xd),D(0xe),D(0xf), - E(0x0),E(0x1),E(0x2),E(0x3),E(0x4),E(0x5),E(0x6),E(0x7), - E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf), - F(0x0),F(0x1),F(0x2),F(0x3),F(0x4) -}; - -// Added minor C++ compile fixes - -size_t _mbsrtowcs(wchar_t * ws, const char **src, size_t wn, mbstate_t *st) -{ - const unsigned char *s = (const unsigned char *)*src; - size_t wn0 = wn; - unsigned c = 0; - - if (st && (c = *(unsigned *)st)) { - if (ws) { - *(unsigned *)st = 0; - goto resume; - } else { - goto resume0; - } - } - - if (!ws) for (;;) { - if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { - while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { - s += 4; - wn -= 4; - } - } - if (*s-1u < 0x7f) { - s++; - wn--; - continue; - } - if (*s-SA > SB-SA) break; - c = bittab[*s++-SA]; -resume0: - if (OOB(c,*s)) { s--; break; } - s++; - if (c&(1U<<25)) { - if (*s-0x80u >= 0x40) { s-=2; break; } - s++; - if (c&(1U<<19)) { - if (*s-0x80u >= 0x40) { s-=3; break; } - s++; - } - } - wn--; - c = 0; - } else for (;;) { - if (!wn) { - *src = (const char *)s; - return wn0; - } - if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { - while (wn>=5 && !(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - *ws++ = *s++; - wn -= 4; - } - } - if (*s-1u < 0x7f) { - *ws++ = *s++; - wn--; - continue; - } - if (*s-SA > SB-SA) break; - c = bittab[*s++-SA]; -resume: - if (OOB(c,*s)) { s--; break; } - c = (c<<6) | *s++-0x80; - if (c&(1U<<31)) { - if (*s-0x80u >= 0x40) { s-=2; break; } - c = (c<<6) | *s++-0x80; - if (c&(1U<<31)) { - if (*s-0x80u >= 0x40) { s-=3; break; } - c = (c<<6) | *s++-0x80; - } - } - *ws++ = c; - wn--; - c = 0; - } - - if (!c && !*s) { - if (ws) { - *ws = 0; - *src = 0; - } - return wn0-wn; - } - errno = EILSEQ; - if (ws) *src = (const char *)s; - return -1; -} - -#endif \ No newline at end of file diff --git a/project/src/text/Font.cpp b/project/src/text/Font.cpp index 8234ccad30..4465336abf 100644 --- a/project/src/text/Font.cpp +++ b/project/src/text/Font.cpp @@ -994,12 +994,7 @@ namespace lime { len = sfnt_name.string_len; family_name = new wchar_t[len + 1]; - #if defined(ANDROID) && !defined(HXCPP_CLANG) - // Fix some devices (Android 4.x or older) that have a bad stdc implementation - _mbsrtowcs (family_name, (const char**)&sfnt_name.string, len, 0); - #else mbstowcs (family_name, (const char*)sfnt_name.string, len); - #endif family_name[len] = L'\0'; return family_name; diff --git a/project/src/vm/NekoVM.cpp b/project/src/vm/NekoVM.cpp deleted file mode 100644 index 9376309ecf..0000000000 --- a/project/src/vm/NekoVM.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include - - -extern "C" { void std_main (); } - - -namespace lime { - - - static void report( neko_vm *vm, value exc, int isexc ) { - int i; - buffer b = alloc_buffer(NULL); - value st = neko_exc_stack(vm); - for(i=0;i, reflectType:Class, functionType:Class, hxObjectype:Class):Void; - static function Load(name:String, func:String, numArgs:Int):Dynamic; - function CallMult(args:Dynamic):Dynamic; - function Call0():Dynamic; - function Call1(arg1:Dynamic):Dynamic; - function Call2(arg1:Dynamic, arg2:Dynamic):Dynamic; - function Call3(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic):Dynamic; - function Call4(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic, arg4:Dynamic):Dynamic; - function Call5(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic, arg4:Dynamic, arg5:Dynamic):Dynamic; -} diff --git a/src/lime/_internal/backend/native/NativeApplication.hx b/src/lime/_internal/backend/native/NativeApplication.hx index 1c0486703c..b36aa30faf 100644 --- a/src/lime/_internal/backend/native/NativeApplication.hx +++ b/src/lime/_internal/backend/native/NativeApplication.hx @@ -122,30 +122,10 @@ class NativeApplication NativeCFFI.lime_window_event_manager_register(handleWindowEvent, windowEventInfo); #end - #if (nodejs && lime_cffi) - NativeCFFI.lime_application_init(handle); - - var eventLoop = function() - { - var active = NativeCFFI.lime_application_update(handle); - - if (!active) - { - untyped process.exitCode = NativeCFFI.lime_application_quit(handle); - parent.onExit.dispatch(untyped process.exitCode); - } - else - { - untyped setImmediate(eventLoop); - } - } - - untyped setImmediate(eventLoop); - return 0; - #elseif lime_cffi + #if lime_cffi var result = NativeCFFI.lime_application_exec(handle); - #if (!webassembly && !ios && !nodejs) + #if (!webassembly && !ios) parent.onExit.dispatch(result); #end diff --git a/src/lime/_internal/backend/native/NativeCFFI.hx b/src/lime/_internal/backend/native/NativeCFFI.hx index 83d33f209f..25ccada683 100644 --- a/src/lime/_internal/backend/native/NativeCFFI.hx +++ b/src/lime/_internal/backend/native/NativeCFFI.hx @@ -231,8 +231,6 @@ class NativeCFFI @:cffi private static function lime_mouse_event_manager_register(callback:Dynamic, eventObject:Dynamic):Void; - @:cffi private static function lime_neko_execute(module:String):Void; - @:cffi private static function lime_png_decode_bytes(data:Dynamic, decodeData:Bool, buffer:Dynamic):Dynamic; @:cffi private static function lime_png_decode_file(path:String, decodeData:Bool, buffer:Dynamic):Dynamic; @@ -523,7 +521,6 @@ class NativeCFFI false)); private static var lime_mouse_event_manager_register = new cpp.Callablecpp.Object->cpp.Void>(cpp.Prime._loadPrime("lime", "lime_mouse_event_manager_register", "oov", false)); - private static var lime_neko_execute = new cpp.Callablecpp.Void>(cpp.Prime._loadPrime("lime", "lime_neko_execute", "sv", false)); private static var lime_png_decode_bytes = new cpp.CallableBool->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_png_decode_bytes", "oboo", false)); private static var lime_png_decode_file = new cpp.CallableBool->cpp.Object->cpp.Object>(cpp.Prime._loadPrime("lime", "lime_png_decode_file", @@ -733,7 +730,6 @@ class NativeCFFI private static var lime_lzma_compress = CFFI.load("lime", "lime_lzma_compress", 2); private static var lime_lzma_decompress = CFFI.load("lime", "lime_lzma_decompress", 2); private static var lime_mouse_event_manager_register = CFFI.load("lime", "lime_mouse_event_manager_register", 2); - private static var lime_neko_execute = CFFI.load("lime", "lime_neko_execute", 1); private static var lime_png_decode_bytes = CFFI.load("lime", "lime_png_decode_bytes", 3); private static var lime_png_decode_file = CFFI.load("lime", "lime_png_decode_file", 3); private static var lime_render_event_manager_register = CFFI.load("lime", "lime_render_event_manager_register", 2); @@ -1159,7 +1155,6 @@ class NativeCFFI @:hlNative("lime", "hl_mouse_event_manager_register") private static function lime_mouse_event_manager_register(callback:Void->Void, eventObject:MouseEventInfo):Void {} - // @:cffi private static function lime_neko_execute (module:String):Void; @:hlNative("lime", "hl_png_decode_bytes") private static function lime_png_decode_bytes(data:Bytes, decodeData:Bool, buffer:ImageBuffer):ImageBuffer { return null; diff --git a/src/lime/_internal/backend/native/NativeWindow.hx b/src/lime/_internal/backend/native/NativeWindow.hx index 83bb4a0c26..88f33b54e9 100644 --- a/src/lime/_internal/backend/native/NativeWindow.hx +++ b/src/lime/_internal/backend/native/NativeWindow.hx @@ -431,16 +431,7 @@ class NativeWindow default: #if (!macro && lime_cffi) - #if !cs imageBuffer = NativeCFFI.lime_window_read_pixels(handle, rect, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); - #else - var data:Dynamic = NativeCFFI.lime_window_read_pixels(handle, rect, null); - if (data != null) - { - imageBuffer = new ImageBuffer(new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)), data.width, data.height, - data.bitsPerPixel); - } - #end #end if (imageBuffer != null) diff --git a/src/lime/_internal/format/Deflate.hx b/src/lime/_internal/format/Deflate.hx index ad2d9965b3..16b8ee3bb1 100644 --- a/src/lime/_internal/format/Deflate.hx +++ b/src/lime/_internal/format/Deflate.hx @@ -16,13 +16,7 @@ class Deflate public static function compress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_deflate_compress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_deflate_compress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").deflateRaw")(bytes.getData()); @@ -46,13 +40,7 @@ class Deflate public static function decompress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_deflate_decompress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_deflate_decompress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").inflateRaw")(bytes.getData()); diff --git a/src/lime/_internal/format/GZip.hx b/src/lime/_internal/format/GZip.hx index 36a8b60ed1..4386d5cd18 100644 --- a/src/lime/_internal/format/GZip.hx +++ b/src/lime/_internal/format/GZip.hx @@ -13,13 +13,7 @@ class GZip public static function compress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_gzip_compress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_gzip_compress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").gzip")(bytes.getData()); @@ -35,13 +29,7 @@ class GZip public static function decompress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_gzip_decompress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_gzip_decompress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").ungzip")(bytes.getData()); diff --git a/src/lime/_internal/format/JPEG.hx b/src/lime/_internal/format/JPEG.hx index 23ac83290f..ba54ee7bbc 100644 --- a/src/lime/_internal/format/JPEG.hx +++ b/src/lime/_internal/format/JPEG.hx @@ -29,23 +29,12 @@ class JPEG public static function decodeBytes(bytes:Bytes, decodeData:Bool = true):Image { #if (lime_cffi && !macro) - #if !cs var buffer = NativeCFFI.lime_jpeg_decode_bytes(bytes, decodeData, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); if (buffer != null) { return new Image(buffer); } - #else - var bufferData:Dynamic = NativeCFFI.lime_jpeg_decode_bytes(bytes, decodeData, null); - - if (bufferData != null) - { - var buffer = new ImageBuffer(bufferData.data, bufferData.width, bufferData.height, bufferData.bpp, bufferData.format); - buffer.transparent = bufferData.transparent; - return new Image(buffer); - } - #end #end return null; @@ -54,23 +43,12 @@ class JPEG public static function decodeFile(path:String, decodeData:Bool = true):Image { #if (lime_cffi && !macro) - #if !cs var buffer = NativeCFFI.lime_jpeg_decode_file(path, decodeData, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); if (buffer != null) { return new Image(buffer); } - #else - var bufferData:Dynamic = NativeCFFI.lime_jpeg_decode_file(path, decodeData, null); - - if (bufferData != null) - { - var buffer = new ImageBuffer(bufferData.data, bufferData.width, bufferData.height, bufferData.bpp, bufferData.format); - buffer.transparent = bufferData.transparent; - return new Image(buffer); - } - #end #end return null; @@ -87,16 +65,10 @@ class JPEG image.format = RGBA32; } - #if java - #elseif (sys && lime_cffi && (!disable_cffi || !format) && !macro) + #if (sys && lime_cffi && (!disable_cffi || !format) && !macro) if (CFFI.enabled) { - #if !cs return NativeCFFI.lime_image_encode(image.buffer, 1, quality, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_image_encode(image.buffer, 1, quality, null); - return @:privateAccess new Bytes(data.length, data.b); - #end } #end @@ -131,11 +103,7 @@ class JPEG if (image.buffer.__srcCanvas != null) { var data = image.buffer.__srcCanvas.toDataURL("image/jpeg", quality / 100); - #if nodejs - var buffer = new js.node.Buffer((data.split(";base64,")[1] : String), "base64").toString("binary"); - #else var buffer = Browser.window.atob(data.split(";base64,")[1]); - #end var bytes = Bytes.alloc(buffer.length); for (i in 0...buffer.length) diff --git a/src/lime/_internal/format/LZMA.hx b/src/lime/_internal/format/LZMA.hx index 47510fecd4..fd5f7be5ba 100644 --- a/src/lime/_internal/format/LZMA.hx +++ b/src/lime/_internal/format/LZMA.hx @@ -18,13 +18,7 @@ class LZMA public static function compress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_lzma_compress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_lzma_compress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("LZMA.compress")(new UInt8Array(bytes.getData()), 5); if ((data is String)) @@ -51,13 +45,7 @@ class LZMA public static function decompress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_lzma_decompress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_lzma_decompress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("LZMA.decompress")(new UInt8Array(bytes.getData())); if ((data is String)) diff --git a/src/lime/_internal/format/PNG.hx b/src/lime/_internal/format/PNG.hx index 33bce0bdde..d95192153c 100644 --- a/src/lime/_internal/format/PNG.hx +++ b/src/lime/_internal/format/PNG.hx @@ -29,23 +29,12 @@ class PNG public static function decodeBytes(bytes:Bytes, decodeData:Bool = true):Image { #if (lime_cffi && !macro) - #if !cs var buffer = NativeCFFI.lime_png_decode_bytes(bytes, decodeData, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); if (buffer != null) { return new Image(buffer); } - #else - var bufferData:Dynamic = NativeCFFI.lime_png_decode_bytes(bytes, decodeData, null); - - if (bufferData != null) - { - var buffer = new ImageBuffer(bufferData.data, bufferData.width, bufferData.height, bufferData.bpp, bufferData.format); - buffer.transparent = bufferData.transparent; - return new Image(buffer); - } - #end #end return null; @@ -54,23 +43,12 @@ class PNG public static function decodeFile(path:String, decodeData:Bool = true):Image { #if (lime_cffi && !macro) - #if !cs var buffer = NativeCFFI.lime_png_decode_file(path, decodeData, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); if (buffer != null) { return new Image(buffer); } - #else - var bufferData:Dynamic = NativeCFFI.lime_png_decode_file(path, decodeData, null); - - if (bufferData != null) - { - var buffer = new ImageBuffer(bufferData.data, bufferData.width, bufferData.height, bufferData.bpp, bufferData.format); - buffer.transparent = bufferData.transparent; - return new Image(buffer); - } - #end #end return null; @@ -87,16 +65,10 @@ class PNG image.format = RGBA32; } - #if java - #elseif (sys && lime_cffi && (!disable_cffi || !format) && !macro) + #if (sys && lime_cffi && (!disable_cffi || !format) && !macro) if (CFFI.enabled) { - #if !cs return NativeCFFI.lime_image_encode(image.buffer, 0, 0, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_image_encode(image.buffer, 0, 0, null); - return @:privateAccess new Bytes(data.length, data.b); - #end } #end @@ -147,11 +119,7 @@ class PNG if (image.buffer.__srcCanvas != null) { var data = image.buffer.__srcCanvas.toDataURL("image/png"); - #if nodejs - var buffer = new js.node.Buffer((data.split(";base64,")[1] : String), "base64").toString("binary"); - #else var buffer = Browser.window.atob(data.split(";base64,")[1]); - #end var bytes = Bytes.alloc(buffer.length); for (i in 0...buffer.length) diff --git a/src/lime/_internal/format/Zlib.hx b/src/lime/_internal/format/Zlib.hx index 4a891c4a4c..57bbb84cb8 100644 --- a/src/lime/_internal/format/Zlib.hx +++ b/src/lime/_internal/format/Zlib.hx @@ -16,13 +16,7 @@ class Zlib public static function compress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_zlib_compress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_zlib_compress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").deflate")(bytes.getData()); @@ -46,13 +40,7 @@ class Zlib public static function decompress(bytes:Bytes):Bytes { #if (lime_cffi && !macro) - #if !cs return NativeCFFI.lime_zlib_decompress(bytes, Bytes.alloc(0)); - #else - var data:Dynamic = NativeCFFI.lime_zlib_decompress(bytes, null); - if (data == null) return null; - return @:privateAccess new Bytes(data.length, data.b); - #end #elseif js #if commonjs var data = untyped #if haxe4 js.Syntax.code #else __js__ #end ("require (\"pako\").inflate")(bytes.getData()); diff --git a/src/lime/_internal/macros/DefineMacro.hx b/src/lime/_internal/macros/DefineMacro.hx index 3359583b87..6763464eb6 100644 --- a/src/lime/_internal/macros/DefineMacro.hx +++ b/src/lime/_internal/macros/DefineMacro.hx @@ -28,15 +28,12 @@ class DefineMacro } else if (Context.defined("js")) { - if (!Context.defined("nodejs")) - { - Compiler.define("html5"); - Compiler.define("web"); - Compiler.define("lime-canvas"); - Compiler.define("lime-dom"); - Compiler.define("lime-howlerjs"); - Compiler.define("lime-webgl"); - } + Compiler.define("html5"); + Compiler.define("web"); + Compiler.define("lime-canvas"); + Compiler.define("lime-dom"); + Compiler.define("lime-howlerjs"); + Compiler.define("lime-webgl"); } else { @@ -44,7 +41,7 @@ class DefineMacro var cffi = (!Context.defined("nocffi") && !Context.defined("eval")); - if (Context.defined("ios") || Context.defined("android") || Context.defined("tizen")) + if (Context.defined("ios") || Context.defined("android")) { Compiler.define("mobile"); if (cffi) Compiler.define("lime-opengles"); diff --git a/src/lime/graphics/Image.hx b/src/lime/graphics/Image.hx index 97385cdc3a..54894e95ec 100644 --- a/src/lime/graphics/Image.hx +++ b/src/lime/graphics/Image.hx @@ -1483,18 +1483,7 @@ class Image __fromBase64(Base64.encode(bytes), type, onload); return true; #elseif (lime_cffi && !macro) - var imageBuffer:ImageBuffer = null; - - #if !cs - imageBuffer = NativeCFFI.lime_image_load_bytes(bytes, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); - #else - var data = NativeCFFI.lime_image_load_bytes(bytes, null); - if (data != null) - { - imageBuffer = new ImageBuffer(new UInt8Array(@:privateAccess new Bytes(data.data.buffer.length, data.data.buffer.b)), data.width, data.height, - data.bitsPerPixel); - } - #end + var imageBuffer:ImageBuffer = NativeCFFI.lime_image_load_bytes(bytes, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); if (imageBuffer != null) { @@ -1555,24 +1544,15 @@ class Image if (image.complete) {} return true; - #elseif (lime_cffi || java) + #elseif (lime_cffi) var buffer:ImageBuffer = null; - #if (!sys || disable_cffi || java || macro) + #if (!sys || disable_cffi || macro) if (false) {} #else if (CFFI.enabled) { - #if !cs buffer = NativeCFFI.lime_image_load_file(path, new ImageBuffer(new UInt8Array(Bytes.alloc(0)))); - #else - var data = NativeCFFI.lime_image_load_file(path, null); - if (data != null) - { - buffer = new ImageBuffer(new UInt8Array(@:privateAccess new Bytes(data.data.buffer.length, data.data.buffer.b)), data.width, data.height, - data.bitsPerPixel); - } - #end } #end diff --git a/src/lime/graphics/ImageBuffer.hx b/src/lime/graphics/ImageBuffer.hx index fddbe81d48..bf2b1b4cf3 100644 --- a/src/lime/graphics/ImageBuffer.hx +++ b/src/lime/graphics/ImageBuffer.hx @@ -159,14 +159,6 @@ class ImageBuffer { buffer.__srcImage = __srcImage; } - #elseif nodejs - if (data != null) - { - buffer.data = new UInt8Array(data.byteLength); - var copy = new UInt8Array(data); - buffer.data.set(copy); - } - buffer.__srcCustom = __srcCustom; #else if (data != null) { diff --git a/src/lime/graphics/cairo/CairoImageSurface.hx b/src/lime/graphics/cairo/CairoImageSurface.hx index d765c98667..9fc470a773 100644 --- a/src/lime/graphics/cairo/CairoImageSurface.hx +++ b/src/lime/graphics/cairo/CairoImageSurface.hx @@ -35,7 +35,7 @@ import lime.utils.DataPointer; public static function fromImage(image:Image):CairoSurface { #if (lime_cffi && lime_cairo && !macro) - return create(#if nodejs image.data #else image.data.buffer #end, CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); + return create(image.data.buffer, CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); #else return null; #end diff --git a/src/lime/media/AudioBuffer.hx b/src/lime/media/AudioBuffer.hx index e74b531ec3..b8317b328f 100644 --- a/src/lime/media/AudioBuffer.hx +++ b/src/lime/media/AudioBuffer.hx @@ -33,10 +33,10 @@ import flash.net.URLRequest; #end /** - The `AudioBuffer` class represents a buffer of audio data that can be played back using an `AudioSource`. + The `AudioBuffer` class represents a buffer of audio data that can be played back using an `AudioSource`. It supports a variety of audio formats and platforms, providing a consistent API for loading and managing audio data. - Depending on the platform, the audio backend may differ, but the class provides a unified interface for accessing + Depending on the platform, the audio backend may differ, but the class provides a unified interface for accessing audio data, whether it's stored in memory, loaded from a file, or streamed. @see lime.media.AudioSource @@ -122,32 +122,13 @@ class AudioBuffer audioBuffer.src = new Howl({src: [base64String], html5: true, preload: false}); return audioBuffer; #elseif (lime_cffi && !macro) - #if !cs // if base64String contains codec data, strip it then decode it. var base64StringSplit = base64String.split(","); var base64StringNoEncoding = base64StringSplit[base64StringSplit.length - 1]; var bytes:Bytes = Base64.decode(base64StringNoEncoding); var audioBuffer = new AudioBuffer(); audioBuffer.data = new UInt8Array(Bytes.alloc(0)); - return NativeCFFI.lime_audio_load_bytes(bytes, audioBuffer); - #else - // if base64String contains codec data, strip it then decode it. - var base64StringSplit = base64String.split(","); - var base64StringNoEncoding = base64StringSplit[base64StringSplit.length - 1]; - var bytes:Bytes = Base64.decode(base64StringNoEncoding); - var data:Dynamic = NativeCFFI.lime_audio_load_bytes(bytes, null); - - if (data != null) - { - var audioBuffer = new AudioBuffer(); - audioBuffer.bitsPerSample = data.bitsPerSample; - audioBuffer.channels = data.channels; - audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); - audioBuffer.sampleRate = data.sampleRate; - return audioBuffer; - } - #end #end return null; @@ -169,24 +150,9 @@ class AudioBuffer return audioBuffer; #elseif (lime_cffi && !macro) - #if !cs var audioBuffer = new AudioBuffer(); audioBuffer.data = new UInt8Array(Bytes.alloc(0)); - return NativeCFFI.lime_audio_load_bytes(bytes, audioBuffer); - #else - var data:Dynamic = NativeCFFI.lime_audio_load_bytes(bytes, null); - - if (data != null) - { - var audioBuffer = new AudioBuffer(); - audioBuffer.bitsPerSample = data.bitsPerSample; - audioBuffer.channels = data.channels; - audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); - audioBuffer.sampleRate = data.sampleRate; - return audioBuffer; - } - #end #end return null; @@ -224,27 +190,10 @@ class AudioBuffer audioBuffer.__srcSound = new Sound(new URLRequest(path)); return audioBuffer; #elseif (lime_cffi && !macro) - #if !cs var audioBuffer = new AudioBuffer(); audioBuffer.data = new UInt8Array(Bytes.alloc(0)); - return NativeCFFI.lime_audio_load_file(path, audioBuffer); #else - var data:Dynamic = NativeCFFI.lime_audio_load_file(path, null); - - if (data != null) - { - var audioBuffer = new AudioBuffer(); - audioBuffer.bitsPerSample = data.bitsPerSample; - audioBuffer.channels = data.channels; - audioBuffer.data = new UInt8Array(@:privateAccess new Bytes(data.data.length, data.data.b)); - audioBuffer.sampleRate = data.sampleRate; - return audioBuffer; - } - - return null; - #end - #else return null; #end } @@ -287,7 +236,7 @@ class AudioBuffer @return An `AudioBuffer` instance with the decoded audio data. **/ #if lime_vorbis - + public static function fromVorbisFile(vorbisFile:VorbisFile):AudioBuffer { if (vorbisFile == null) return null; diff --git a/src/lime/system/CFFI.hx b/src/lime/system/CFFI.hx index 3f512807ec..a9b5910996 100644 --- a/src/lime/system/CFFI.hx +++ b/src/lime/system/CFFI.hx @@ -16,8 +16,6 @@ class CFFI @:noCompletion private static var __moduleNames:Map = null; #if neko private static var __loadedNekoAPI:Bool; - #elseif nodejs - private static var __nodeNDLLModule:Dynamic; #end public static var available:Bool; public static var enabled:Bool; @@ -80,8 +78,6 @@ class CFFI { #if neko result = neko.Lib.loadLazy(library, method, args); - #elseif java - result = __loadJava(library, method, args); #elseif cpp result = cpp.Lib.loadLazy(library, method, args); #end @@ -111,12 +107,6 @@ class CFFI #else return neko.Lib.load(__moduleNames.get(library), method, args); #end - #elseif nodejs - return untyped __nodeNDLLModule.load_lib(__moduleNames.get(library), method, args); - #elseif java - result = __loadJava(__moduleNames.get(library), method, args); - #elseif cs - return untyped CSFunctionLoader.load(__moduleNames.get(library), method, args); #else return null; #end @@ -127,11 +117,6 @@ class CFFI { flash.Lib.load("waxe", "wx_boot", 1); } - #elseif nodejs - if (__nodeNDLLModule == null) - { - __nodeNDLLModule = untyped require('ndll'); - } #end __moduleNames.set(library, library); @@ -261,27 +246,6 @@ class CFFI #end } - #if java - private static var __loadedLibraries = new Map(); - - private static function __loadJava(library:String, method:String, args:Int = 0) - { - if (!__loadedLibraries.exists(library)) - { - var extension = #if android ".so" #else ".ndll" #end; - var path = Sys.getCwd() + "/" + library + extension; - - java.lang.System.load(path); - - __loadedLibraries.set(library, true); - - trace("load library: " + library); - } - - return null; - } - #end - #if neko private static function __loadNekoAPI(lazy:Bool):Void { @@ -341,14 +305,8 @@ class CFFI { #if cpp var result = cpp.Lib.load(name, func, args); - #elseif (neko) + #elseif neko var result = neko.Lib.load(name, func, args); - #elseif nodejs - var result = untyped __nodeNDLLModule.load_lib(name, func, args); - #elseif java - var result = __loadJava(name, func, args); - #elseif cs - var result = CSFunctionLoader.load(name, func, args); #else var result = null; #end @@ -369,73 +327,4 @@ class CFFI return null; } } - -#if cs -@:dox(hide) private class CSFunctionLoader -{ - public static function load(name:String, func:String, args:Int):Dynamic - { - var func:cs.ndll.NDLLFunction = cs.ndll.NDLLFunction.Load(name, func, args); - - if (func == null) - { - return null; - } - - if (args == -1) - { - var haxeFunc:Dynamic = function(args:Array):Dynamic - { - return func.CallMult(args); - } - - return Reflect.makeVarArgs(haxeFunc); - } - else if (args == 0) - { - return function():Dynamic - { - return func.Call0(); - } - } - else if (args == 1) - { - return function(arg1:Dynamic):Dynamic - { - return func.Call1(arg1); - } - } - else if (args == 2) - { - return function(arg1:Dynamic, arg2:Dynamic):Dynamic - { - return func.Call2(arg1, arg2); - } - } - else if (args == 3) - { - return function(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic):Dynamic - { - return func.Call3(arg1, arg2, arg3); - } - } - else if (args == 4) - { - return function(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic, arg4:Dynamic):Dynamic - { - return func.Call4(arg1, arg2, arg3, arg4); - } - } - else if (args == 5) - { - return function(arg1:Dynamic, arg2:Dynamic, arg3:Dynamic, arg4:Dynamic, arg5:Dynamic):Dynamic - { - return func.Call5(arg1, arg2, arg3, arg4, arg5); - } - } - - return null; - } -} -#end #end diff --git a/src/lime/system/System.hx b/src/lime/system/System.hx index 74a4192b5e..38eac1b07a 100644 --- a/src/lime/system/System.hx +++ b/src/lime/system/System.hx @@ -331,7 +331,7 @@ class System { #if flash return flash.Lib.getTimer(); - #elseif ((js && !nodejs) || electron) + #elseif (js || electron) return Browser.window.performance.now(); #elseif (lime_cffi && !macro && !neko) return NativeCFFI.lime_system_get_timer() / 1e+6; @@ -829,16 +829,6 @@ class System __platformName = "Flash Player"; #elseif tvos __platformName = "tvOS"; - #elseif tizen - __platformName = "Tizen"; - #elseif blackberry - __platformName = "BlackBerry"; - #elseif firefox - __platformName = "Firefox"; - #elseif webos - __platformName = "webOS"; - #elseif nodejs - __platformName = "Node.js"; #elseif js __platformName = "HTML5"; #end diff --git a/src/lime/text/Font.hx b/src/lime/text/Font.hx index 564b267afb..4da51f0f22 100644 --- a/src/lime/text/Font.hx +++ b/src/lime/text/Font.hx @@ -27,7 +27,7 @@ import haxe.io.Path; @:fileXml('tags="haxe,release"') @:noDebug #end -#if (!display && !flash && !nodejs && !macro) +#if (!display && !flash && !macro) @:autoBuild(lime._internal.macros.AssetsMacro.embedFont()) #end @:access(lime._internal.backend.native.NativeCFFI) @@ -38,12 +38,12 @@ class Font * The ascender value of the font. */ public var ascender:Int; - + /** * The descender value of the font. */ public var descender:Int; - + /** * The height of the font. */ @@ -59,7 +59,7 @@ class Font */ public var numGlyphs:Int; - + public var src:Dynamic; /** diff --git a/src/lime/tools/AssetHelper.hx b/src/lime/tools/AssetHelper.hx index 2f9ef857c9..34bf666ff3 100644 --- a/src/lime/tools/AssetHelper.hx +++ b/src/lime/tools/AssetHelper.hx @@ -626,8 +626,6 @@ class AssetHelper if (isPackedLibrary(project, library)) { - // TODO - #if !nodejs if (type == "zip") type = "deflate"; // TODO: Support library.embed=true by embedding all the assets instead of packing @@ -700,7 +698,6 @@ class AssetHelper { library.preload = true; } - #end } } diff --git a/src/lime/tools/CSHelper.hx b/src/lime/tools/CSHelper.hx deleted file mode 100644 index 4443a1f0d0..0000000000 --- a/src/lime/tools/CSHelper.hx +++ /dev/null @@ -1,268 +0,0 @@ -package lime.tools; - -import hxp.*; -import lime.tools.Architecture; -import lime.tools.HXProject; -import sys.io.File; -import sys.FileSystem; - -using StringTools; - -class CSHelper -{ - public static var ndllSourceFiles:Array = [ - "cs.ndll.NDLLFunction", "cs.ndll.CFFICSLoader", "cs.ndll.CSAbstract", "cs.ndll.CSHandleContainer", "cs.ndll.CSHandleScope", "cs.ndll.CSPersistent", - "cs.ndll.DelegateConverter", "cs.ndll.HandleUtils", "cs.ndll.NativeMethods", "cs.ndll.NDLLFunction", - ]; - - private static function getAndroidABIName(arch:Architecture):String - { - var name = switch (arch) - { - case ARMV5: - "armeabi"; - case ARMV7: - "armeabi-v7a"; - case ARM64: - "arm64-v8a"; - case X86: - "x86"; - case X64: - "x86_64"; - case _: - null; - } - - if (name == null) - { - throw "Unsupported architecture:" + arch; - } - - return name; - } - - public static function getAndroidABINames(architectures:Array):String - { - var result = ""; - var first = true; - - for (arch in architectures) - { - if (first) - { - first = false; - } - else - { - result += ","; - } - - var archName = getAndroidABIName(arch); - result += archName; - } - - return result; - } - - public static function getAndroidNativeLibraryPaths(libPath:String, libraries:Array, architectures:Array):Array - { - var paths = []; - - for (arch in architectures) - { - var archName = getAndroidABIName(arch); - - for (lib in libraries) - { - paths.push(FileSystem.absolutePath(libPath + "/" + archName + "/" + "lib" + lib.name + ".so").replace("/", "\\")); - } - } - - return paths; - } - - public static function copySourceFiles(templatePaths:Array, targetPath:String) - { - System.recursiveCopyTemplate(templatePaths, "cs/src", targetPath); - } - - public static function addSourceFiles(txtPath:String, sourceFiles:Array) - { - if (sourceFiles.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin modules\n'); - - for (fileName in sourceFiles) - { - file.writeString('M $fileName\nC $fileName\n'); - } - - file.writeString('end modules\n'); - file.close(); - } - - public static function addAndroidResources(txtPath:String, resources:Array) - { - if (resources.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin android_resources\n'); - - for (resource in resources) - { - file.writeString('$resource\n'); - } - - file.writeString('end android_resources\n'); - file.close(); - } - - public static function addAssemblies(txtPath:String, assemblies:Array) - { - if (assemblies.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin libs\n'); - - for (assembly in assemblies) - { - file.writeString(assembly.replace("/", "\\") + '\n'); - } - - file.writeString('end libs\n'); - file.close(); - } - - public static function addNativeLibraries(txtPath:String, libPath:String, libraries:Array, architectures:Array) - { - if (libraries.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin native_libs\n'); - - for (arch in architectures) - { - var archName = getAndroidABIName(arch); - - for (lib in libraries) - { - file.writeString(FileSystem.absolutePath(libPath + "/" + archName + "/" + "lib" + lib.name + ".so").replace("/", "\\") + '\n'); - } - } - - file.writeString('end native_libs\n'); - file.close(); - } - - public static function addAndroidABIs(txtPath:String, architectures:Array) - { - if (architectures.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin android_abis\n'); - - for (arch in architectures) - { - var archName = getAndroidABIName(arch); - file.writeString(archName + '\n'); - } - - file.writeString('end android_abis\n'); - file.close(); - } - - public static function addAssets(txtPath:String, assets:Array) - { - if (assets.length == 0) - { - return; - } - - var file = File.append(txtPath, false); - file.writeString('\nbegin android_assets\n'); - - for (asset in assets) - { - file.writeString(FileSystem.absolutePath(asset).replace("/", "\\") + '\n'); - } - - file.writeString('end android_assets\n'); - file.close(); - } - - public static function addGUID(txtPath:String, guid:String) - { - var file = File.append(txtPath, false); - file.writeString('\nbegin guid\n'); - - file.writeString('$guid\n'); - - file.writeString('end guid\n'); - file.close(); - } - - public static function compile(project:HXProject, path:String, outPath:String, arch:String, platform:String, buildFile:String = "hxcs_build.txt", - noCompile:Bool = false) - { - var args = [ - "run", - project.config.getString("cs.buildLibrary", "hxcs"), - buildFile, - "--arch", - arch, - "--platform", - platform, - "--out", - outPath, - "--unsafe" - ]; - if (noCompile) args.push("--no-compile"); - var code = Haxelib.runCommand(path, args); - - if (code != 0) - { - Sys.exit(code); - } - } - - public static function buildGradleProj(path:String) - { - var gradlePath = FileSystem.absolutePath(path + "/" + "gradlew"); - System.runCommand(path, gradlePath, ["build", "assembleRelease"]); - } - - inline public static function buildSln(path:String, slnPath:String, task:String = null) - { - buildCSProj(path, slnPath, task); - } - - public static function buildCSProj(path:String, csprojPath:String, task:String = null) - { - var msBuildPath = "C:/Program Files (x86)/MSBuild/14.0/Bin/MSBuild.exe"; - var absCSProjPath = FileSystem.absolutePath(csprojPath); - var args = [absCSProjPath, "/p:Configuration=Release"]; - - if (task != null) - { - args.push("/t:" + task); - } - - System.runCommand(path, msBuildPath, args); - } -} diff --git a/src/lime/tools/HTML5Helper.hx b/src/lime/tools/HTML5Helper.hx index d7550381f1..204e11fcdf 100644 --- a/src/lime/tools/HTML5Helper.hx +++ b/src/lime/tools/HTML5Helper.hx @@ -224,20 +224,6 @@ class HTML5Helper System.runCommand("", executable, args); } - else if (project.targetFlags.exists("yui")) - { - var templatePaths = [ - Path.combine(Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)), #if lime "templates" #else "" #end) - ].concat(project.templatePaths); - System.runCommand("", "java", [ - "-Dapple.awt.UIElement=true", - "-jar", - System.findTemplate(templatePaths, "bin/yuicompressor-2.4.7.jar"), - "-o", - tempFile, - sourceFile - ]); - } else { var executable:String; @@ -296,11 +282,9 @@ class HTML5Helper if (FileSystem.exists(tempFile + ".map")) { // closure does not include a sourceMappingURL in the created .js, we do it here - #if !nodejs var f = File.append(tempFile); f.writeString("//# sourceMappingURL=" + StringTools.urlEncode(Path.withoutDirectory(sourceFile)) + ".map"); f.close(); - #end File.copy(tempFile + ".map", sourceFile + ".map"); FileSystem.deleteFile(tempFile + ".map"); diff --git a/src/lime/tools/HXProject.hx b/src/lime/tools/HXProject.hx index 7c590afada..9fcb7d46f1 100644 --- a/src/lime/tools/HXProject.hx +++ b/src/lime/tools/HXProject.hx @@ -142,10 +142,10 @@ class HXProject extends Script case AIR if (targetFlags.exists("ios") || targetFlags.exists("android")): PlatformType.MOBILE; - case FLASH, HTML5, FIREFOX, WEB_ASSEMBLY: + case FLASH, HTML5, WEB_ASSEMBLY: PlatformType.WEB; - case ANDROID, BLACKBERRY, IOS, TIZEN, WEBOS, TVOS: + case ANDROID, IOS, TVOS: PlatformType.MOBILE; case WINDOWS, MAC, LINUX, AIR: @@ -156,12 +156,6 @@ class HXProject extends Script PlatformType.CONSOLE; } - if (target == WINDOWS && targetFlags.exists("uwp") || targetFlags.exists("winjs")) - { - targetFlags.set("uwp", ""); - targetFlags.set("winjs", ""); - } - meta = {}; app = {}; window = {}; @@ -190,7 +184,7 @@ class HXProject extends Script else { environment = Sys.environment(); - for (conflict in ["air", "android", "cpp", "flash", "hl", "html5", "ios", "linux", "mac", "neko", "webassembly", "windows"]) + for (conflict in ["air", "android", "cpp", "flash", "hl", "html5", "ios", "linux", "mac", "webassembly", "windows"]) { environment.remove(conflict); } @@ -711,13 +705,7 @@ class HXProject extends Script defines.set("console", "1"); } - if (targetFlags.exists("neko")) - { - defines.set("targetType", "neko"); - defines.set("native", "1"); - defines.set("neko", "1"); - } - else if (targetFlags.exists("hl")) + if (targetFlags.exists("hl")) { defines.set("targetType", "hl"); defines.set("native", "1"); @@ -727,29 +715,6 @@ class HXProject extends Script defines.set("hlc", "1"); } } - else if (targetFlags.exists("java")) - { - defines.set("targetType", "java"); - defines.set("native", "1"); - defines.set("java", "1"); - } - else if (targetFlags.exists("nodejs")) - { - defines.set("targetType", "nodejs"); - defines.set("native", "1"); - defines.set("nodejs", "1"); - } - else if (targetFlags.exists("cs")) - { - defines.set("targetType", "cs"); - defines.set("native", "1"); - defines.set("cs", "1"); - } - else if (target == Platform.FIREFOX) - { - defines.set("targetType", "js"); - defines.set("html5", "1"); - } else if (target == Platform.AIR) { defines.set("targetType", "swf"); @@ -757,16 +722,6 @@ class HXProject extends Script if (targetFlags.exists("ios")) defines.set("ios", "1"); if (targetFlags.exists("android")) defines.set("android", "1"); } - else if (target == Platform.WINDOWS && (targetFlags.exists("uwp") || targetFlags.exists("winjs"))) - { - targetFlags.set("uwp", ""); - targetFlags.set("winjs", ""); - - defines.set("targetType", "js"); - defines.set("html5", "1"); - defines.set("uwp", "1"); - defines.set("winjs", "1"); - } else if (platformType == DESKTOP && target != System.hostPlatform) { defines.set("native", "1"); diff --git a/src/lime/tools/JavaHelper.hx b/src/lime/tools/JavaHelper.hx deleted file mode 100644 index ce7d5d4b19..0000000000 --- a/src/lime/tools/JavaHelper.hx +++ /dev/null @@ -1,12 +0,0 @@ -package lime.tools; - -import hxp.*; -import sys.io.File; - -class JavaHelper -{ - public static function copyLibraries(templatePaths:Array, platformName:String, targetPath:String) - { - System.recursiveCopyTemplate(templatePaths, "java/ndll/" + platformName, targetPath); - } -} diff --git a/src/lime/tools/NekoHelper.hx b/src/lime/tools/NekoHelper.hx deleted file mode 100644 index 1367b67636..0000000000 --- a/src/lime/tools/NekoHelper.hx +++ /dev/null @@ -1,71 +0,0 @@ -package lime.tools; - -import hxp.*; -import lime.tools.Platform; -import sys.FileSystem; -import sys.io.File; - -class NekoHelper -{ - public static function copyLibraries(templatePaths:Array, platformName:String, targetPath:String) - { - // System.recursiveCopyTemplate (templatePaths, "neko/ndll/" + platformName, targetPath); - } - - public static function createExecutable(templatePaths:Array, platformName:String, source:String, target:String, iconPath:String = null):Void - { - /*var executablePath = System.findTemplate (templatePaths, "neko/bin/neko-" + platformName); - var executable = File.getBytes (executablePath); - var sourceContents = File.getBytes (source); - - var output = File.write (target, true); - output.write (executable); - output.write (sourceContents); - output.writeString ("NEKO"); - output.writeInt32 (executable.length); - output.close (); */ - - var path = Path.tryFullPath(source); - var file = Path.withoutDirectory(path); - var dir = Path.directory(path); - - System.runCommand(dir, "nekotools", ["boot", file]); - - var path = Path.withoutExtension(source); - - if (System.hostPlatform == WINDOWS) - { - path += ".exe"; - } - - System.copyFile(path, target); - } - - public static function createWindowsExecutable(templatePaths:Array, source:String, target:String, iconPath:String):Void - { - /*var executablePath = System.findTemplate (templatePaths, "neko/bin/neko-windows"); - var executable = File.getBytes (executablePath); - var sourceContents = File.getBytes (source); - - var output = File.write (target, true); - output.write (executable); - output.close (); - - if (iconPath != null && System.hostPlatform == WINDOWS) { - - var templates = [ Haxelib.getPath (new Haxelib (#if lime "lime" #else "hxp" #end)) + "/templates" ].concat (templatePaths); - System.runCommand ("", System.findTemplate (templates, "bin/ReplaceVistaIcon.exe"), [ target, iconPath, "1" ], true, true); - - } - - var executable = File.getBytes (target); - var output = File.write (target, true); - output.write (executable); - output.write (sourceContents); - output.writeString ("NEKO"); - output.writeInt32 (executable.length); - output.close (); */ - - createExecutable(templatePaths, null, source, target, iconPath); - } -} diff --git a/src/lime/tools/Platform.hx b/src/lime/tools/Platform.hx index d799467d1d..f385258753 100644 --- a/src/lime/tools/Platform.hx +++ b/src/lime/tools/Platform.hx @@ -4,9 +4,7 @@ package lime.tools; { var AIR = "air"; var ANDROID = "android"; - var BLACKBERRY = "blackberry"; var CONSOLE_PC = "console-pc"; - var FIREFOX = "firefox"; var FLASH = "flash"; var HTML5 = "html5"; var IOS = "ios"; @@ -14,11 +12,9 @@ package lime.tools; var MAC = "mac"; var PS3 = "ps3"; var PS4 = "ps4"; - var TIZEN = "tizen"; var VITA = "vita"; var WEB_ASSEMBLY = "webassembly"; var WINDOWS = "windows"; - var WEBOS = "webos"; var WIIU = "wiiu"; var XBOX1 = "xbox1"; var EMSCRIPTEN = "emscripten"; diff --git a/src/lime/tools/TizenHelper.hx b/src/lime/tools/TizenHelper.hx deleted file mode 100644 index 0256326e1b..0000000000 --- a/src/lime/tools/TizenHelper.hx +++ /dev/null @@ -1,197 +0,0 @@ -package lime.tools; - -import haxe.crypto.Crc32; -import haxe.io.Bytes; -import haxe.io.Eof; -import hxp.*; -import lime.tools.HXProject; -import lime.tools.Platform; -import sys.FileSystem; - -class TizenHelper -{ - private static var cacheID:String = null; - private static var cacheUUID:String = null; - - public static function createPackage(project:HXProject, workingDirectory:String, targetPath:String):Void - { - var keystore = null; - var password = null; - - if (project.keystore != null) - { - keystore = Path.tryFullPath(project.keystore.path); - password = project.keystore.password; - - if (password == null) - { - password = prompt("Keystore password", true); - Sys.println(""); - } - } - - if (keystore == null) - { - var templatePaths = [ - Path.combine(Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)), #if lime "templates" #else "" #end) - ].concat(project.templatePaths); - keystore = System.findTemplate(templatePaths, "bin/debug.p12"); - password = "1234"; - } - - var packageName = getUUID(project) + "-" + project.meta.version + "-"; - - if (project.targetFlags.exists("simulator")) - { - packageName += "i386"; - } - else - { - packageName += "arm"; - } - - packageName += ".tpk"; - - if (FileSystem.exists(Path.combine(workingDirectory, packageName))) - { - try - { - FileSystem.deleteFile((Path.combine(workingDirectory, packageName))); - } - catch (e:Dynamic) {} - } - - runCommand(project, workingDirectory, "native-packaging", ["--sign-author-key", keystore, "--sign-author-pwd", password]); - } - - public static function getUUID(project:HXProject):String - { - if (cacheID != project.meta.packageName) - { - if (project.meta.packageName != null || project.meta.packageName.length == 10 || project.meta.packageName.indexOf(".") == -1) - { - var bytes = Bytes.ofString(project.meta.packageName); - var crc = Crc32.make(bytes); - cacheUUID = StringTools.generateUUID(10, null, crc); - } - else - { - cacheUUID = project.meta.packageName; - } - - cacheID = project.meta.packageName; - } - - return cacheUUID; - } - - public static function install(project:HXProject, workingDirectory:String):Void - { - var packageName = getUUID(project) + "-" + project.meta.version + "-"; - - if (project.targetFlags.exists("simulator")) - { - packageName += "i386"; - } - else - { - packageName += "arm"; - } - - packageName += ".tpk"; - - runCommand(project, "", "native-install", ["--package", FileSystem.fullPath(workingDirectory + "/" + packageName)]); - } - - public static function launch(project:HXProject):Void - { - runCommand(project, "", "native-run", ["--package", getUUID(project)]); - } - - private static function prompt(name:String, ?passwd:Bool):String - { - Sys.print(name + ": "); - - if (passwd) - { - var s = new StringBuf(); - var c; - while ((c = Sys.getChar(false)) != 13) - s.addChar(c); - return s.toString(); - } - - try - { - return Sys.stdin().readLine(); - } - catch (e:Eof) - { - return ""; - } - } - - private static function runCommand(project:HXProject, workingDirectory:String, command:String, args:Array):Void - { - var sdkDirectory = ""; - - if (project.environment.exists("TIZEN_SDK")) - { - sdkDirectory = project.environment.get("TIZEN_SDK"); - } - else - { - if (System.hostPlatform == WINDOWS) - { - sdkDirectory = "C:\\Development\\Tizen\\tizen-sdk"; - } - else - { - sdkDirectory = "~/Development/Tizen/tizen-sdk"; - } - } - - System.runCommand(workingDirectory, Path.combine(sdkDirectory, "tools/ide/bin/" + command), args); - } - - public static function trace(project:HXProject, follow:Bool = true):Void - { - /*var args = []; - - if (follow) { - - args.push ("-f"); - - } - - args.push (project.meta.packageName); - - runPalmCommand (project, "", "log", args); */ - - var sdkDirectory = ""; - - if (project.environment.exists("TIZEN_SDK")) - { - sdkDirectory = project.environment.get("TIZEN_SDK"); - } - else - { - if (System.hostPlatform == WINDOWS) - { - sdkDirectory = "C:\\Development\\Tizen\\tizen-sdk"; - } - else - { - sdkDirectory = "~/Development/Tizen/tizen-sdk"; - } - } - - // var args = [ "--package", project.meta.packageName ]; - // var args = [ "dlog", project.meta.packageName + ":V", "*:E" ]; - var args = ["dlog", project.app.file + ":V", "*:F"]; - - System.runCommand("", Path.combine(sdkDirectory, "tools/sdb"), ["dlog", "-c"]); - System.runCommand("", Path.combine(sdkDirectory, "tools/sdb"), args); - // runCommand (project, "", "native-debug", [ "-p", project.meta.packageName ]); - } -} diff --git a/src/lime/utils/Bytes.hx b/src/lime/utils/Bytes.hx index 8574601601..3d95ee9465 100644 --- a/src/lime/utils/Bytes.hx +++ b/src/lime/utils/Bytes.hx @@ -92,14 +92,9 @@ abstract Bytes(HaxeBytes) from HaxeBytes to HaxeBytes public static function fromFile(path:String):Bytes { #if (sys && lime_cffi && !macro) - #if !cs var bytes = Bytes.alloc(0); NativeCFFI.lime_bytes_read_file(path, bytes); if (bytes.length > 0) return bytes; - #else - var data:Dynamic = NativeCFFI.lime_bytes_read_file(path, null); - if (data != null) return new Bytes(data.length, data.b); - #end #end return null; } diff --git a/templates/bin/yuicompressor-2.4.7.jar b/templates/bin/yuicompressor-2.4.7.jar deleted file mode 100644 index 3c9a408aac..0000000000 Binary files a/templates/bin/yuicompressor-2.4.7.jar and /dev/null differ diff --git a/templates/blackberry/hxml/debug.hxml b/templates/blackberry/hxml/debug.hxml deleted file mode 100644 index 305519a5c8..0000000000 --- a/templates/blackberry/hxml/debug.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D blackberry --debug diff --git a/templates/blackberry/hxml/final.hxml b/templates/blackberry/hxml/final.hxml deleted file mode 100644 index 1c9b26d876..0000000000 --- a/templates/blackberry/hxml/final.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D blackberry --D final diff --git a/templates/blackberry/hxml/release.hxml b/templates/blackberry/hxml/release.hxml deleted file mode 100644 index 3da413b6df..0000000000 --- a/templates/blackberry/hxml/release.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D blackberry diff --git a/templates/blackberry/template/bar-descriptor.xml b/templates/blackberry/template/bar-descriptor.xml deleted file mode 100644 index 79014cf621..0000000000 --- a/templates/blackberry/template/bar-descriptor.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - ::APP_PACKAGE:: - ::APP_TITLE:: - ::APP_DESCRIPTION:: - - ::APP_COMPANY:: - ::BLACKBERRY_AUTHOR_ID:: - - ::APP_VERSION:: - ::APP_BUILD_NUMBER:: - - - - none - false - - ::if (WIN_ORIENTATION == "landscape")::falselandscape::end:: - ::if (WIN_ORIENTATION == "portrait")::falseportrait::end:: - - - - - - run_native - - core.games - - ::APP_FILE_SAFE:: - . - - ::if (HAS_ICON):: - ::foreach ICONS:: ::__current__:: - ::end::::end:: - - - - \ No newline at end of file diff --git a/templates/blackberry/template/config.xml b/templates/blackberry/template/config.xml deleted file mode 100644 index 628798d4b6..0000000000 --- a/templates/blackberry/template/config.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - ::APP_COMPANY:: - - ::APP_TITLE:: - - ::APP_DESCRIPTION:: - - - - - -::if (HAS_ICON)::::foreach ICONS:: ::end::::end:: - - - - - - - - ::if (WIN_ORIENTATION == "landscape"):: - - ::end:: - - ::if (WIN_ORIENTATION == "portrait"):: - - ::end:: - - - - - - - - - - \ No newline at end of file diff --git a/templates/cs/hxml/debug.hxml b/templates/cs/hxml/debug.hxml deleted file mode 100644 index c71d56b227..0000000000 --- a/templates/cs/hxml/debug.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --D net-ver=40 --cp ::OUTPUT_DIR::/haxe --cs ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") --debug \ No newline at end of file diff --git a/templates/cs/hxml/final.hxml b/templates/cs/hxml/final.hxml deleted file mode 100644 index 914dc1efe4..0000000000 --- a/templates/cs/hxml/final.hxml +++ /dev/null @@ -1,7 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --D net-ver=40 --D real-position --cp ::OUTPUT_DIR::/haxe --cs ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") --D final \ No newline at end of file diff --git a/templates/cs/hxml/release.hxml b/templates/cs/hxml/release.hxml deleted file mode 100644 index b2f464ee62..0000000000 --- a/templates/cs/hxml/release.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --D net-ver=40 --D real-position --cp ::OUTPUT_DIR::/haxe --cs ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") \ No newline at end of file diff --git a/templates/cs/src/cs/ndll/CFFICSLoader.cs b/templates/cs/src/cs/ndll/CFFICSLoader.cs deleted file mode 100644 index 223adc7f9c..0000000000 --- a/templates/cs/src/cs/ndll/CFFICSLoader.cs +++ /dev/null @@ -1,815 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; -using haxe.lang; - -namespace cs.ndll -{ - class CFFICSLoader - { - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - internal delegate IntPtr CFFILoaderDelegate(String inName); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int ValTypeDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int AllocKindDelegate(); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocAbstractDelegate(int arg1, IntPtr arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void FreeAbstractDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValToKindDelegate(IntPtr arg1, int arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValDataDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValArrayIntDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocBoolDelegate([MarshalAs(UnmanagedType.I1)]bool arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocNullDelegate(); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr CreateRootDelegate(IntPtr inValue); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr QueryRootDelegate(IntPtr inValue); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void DestroyRootDelegate(IntPtr inValue); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void ValGCDelegate(IntPtr arg1, CSAbstract.FinalizerDelegate arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate double ValNumberDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int ValStrLenDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValStringDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int ValIntDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocIntDelegate(int arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocArrayDelegate(int arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocArrayTypeDelegate(int arg1, hxValueType arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int ValArraySizeDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValArrayIDelegate(IntPtr arg1, int arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void ValArraySetIDelegate(IntPtr arg1, int arg2, IntPtr arg3); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void ValArrayPushDelegate(IntPtr arg1, IntPtr arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int ValIdDelegate(String arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void AllocFieldDelegate(IntPtr arg1, int arg2, IntPtr arg3); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValCall0Delegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocEmptyObjectDelegate(); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocStringLenDelegate(IntPtr inStr, int inLen); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocWStringLenDelegate(IntPtr inStr, int inLen); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocFloatDelegate(double arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr AllocBufferLenDelegate(int inLen); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr BufferDataDelegate(IntPtr inBuffer); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr BufferValDelegate(IntPtr b); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValToBufferDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void BufferSetSizeDelegate(IntPtr inBuffer, int inLen); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate int BufferSizeDelegate(IntPtr inBuffer); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr PinBufferDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void UnPinBufferDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr ValFieldDelegate(IntPtr arg1, int arg2); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate bool ValBoolDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void ValThrowDelegate(IntPtr arg1); - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr EmptyDelegate(); - - private enum hxValueType - { - valtUnknown = -1, - valtInt = 0xff, - valtNull = 0, - valtFloat = 1, - valtBool = 2, - valtString = 3, - valtObject = 4, - valtArray = 5, - valtFunction = 6, - valtEnum, - valtClass, - valtRoot = 0xff, - valtAbstractBase = 0x100, - }; - - private static int sgKinds = (int)(hxValueType.valtAbstractBase + 2); - - private static DelegateConverter val_type; - private static DelegateConverter alloc_kind; - private static DelegateConverter alloc_abstract; - private static DelegateConverter free_abstract; - private static DelegateConverter val_to_kind; - private static DelegateConverter val_data; - private static DelegateConverter val_array_int; - private static DelegateConverter alloc_bool; - private static DelegateConverter alloc_null; - private static DelegateConverter create_root; - private static DelegateConverter query_root; - private static DelegateConverter destroy_root; - private static DelegateConverter val_gc; - private static DelegateConverter val_number; - private static DelegateConverter val_strlen; - private static DelegateConverter val_string; - private static DelegateConverter val_int; - private static DelegateConverter alloc_int; - private static DelegateConverter alloc_array; - private static DelegateConverter alloc_array_type; - private static DelegateConverter val_array_size; - private static DelegateConverter val_array_i; - private static DelegateConverter val_array_set_i; - private static DelegateConverter val_array_push; - private static DelegateConverter val_id; - private static DelegateConverter alloc_field; - private static DelegateConverter val_call0; - private static DelegateConverter alloc_empty_object; - private static DelegateConverter alloc_string_len; - private static DelegateConverter alloc_wstring_len; - private static DelegateConverter alloc_float; - private static DelegateConverter alloc_buffer_len; - private static DelegateConverter buffer_data; - private static DelegateConverter buffer_val; - private static DelegateConverter val_to_buffer; - private static DelegateConverter buffer_set_size; - private static DelegateConverter buffer_size; - private static DelegateConverter pin_buffer; - private static DelegateConverter unpin_buffer; - private static DelegateConverter val_field; - private static DelegateConverter val_bool; - private static DelegateConverter val_throw; - private static DelegateConverter empty; - - private static int cs_val_type(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return (int)hxValueType.valtNull; - - if (arg1 is Boolean) - return (int)hxValueType.valtBool; - else if (arg1 is sbyte || - arg1 is byte || - arg1 is short || - arg1 is ushort || - arg1 is int || - arg1 is uint || - arg1 is long || - arg1 is ulong) - return (int)hxValueType.valtInt; - else if (arg1 is float || - arg1 is double || - arg1 is decimal) - return (int)hxValueType.valtFloat; - else if (arg1 is String) - return (int)hxValueType.valtString; - else if (arg1 is Array) - return (int)hxValueType.valtArray; - else if (arg1 is Function) - return (int)hxValueType.valtFunction; - else if (arg1.GetType().IsEnum) - return (int)hxValueType.valtEnum; - else if (arg1.GetType().IsClass) - return (int)hxValueType.valtClass; - else if (arg1 is DynamicObject) - return (int)hxValueType.valtObject; - else if (arg1 is CSAbstract) - return ((CSAbstract)arg1).Kind; - - return (int)hxValueType.valtUnknown; - } - - // Abstract types - private static int cs_alloc_kind() - { - return ++sgKinds; - } - - private static IntPtr cs_alloc_abstract(int arg1, IntPtr arg2) - { - return CSHandleContainer.GetCurrent().CreateGCHandle(new CSAbstract(arg1, arg2)); - } - - private static void cs_free_abstract(IntPtr inArg1) - { - CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1); - arg1.Free(); - } - - private static IntPtr cs_val_to_kind(IntPtr inArg1, int arg2) - { - CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return IntPtr.Zero; - - return arg1.Kind == arg2 ? arg1.Pointer : IntPtr.Zero; - } - - private static IntPtr cs_val_data(IntPtr inArg1) - { - CSAbstract arg1 = (CSAbstract)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return IntPtr.Zero; - - return arg1.Pointer; - } - - private static IntPtr cs_val_array_int(IntPtr inArg1) - { - Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return IntPtr.Zero; - - Array intHxArray = arg1 as Array; - if (intHxArray != null) - return CSHandleContainer.GetCurrent().GetAddrOfBlittableObject(intHxArray.__a); - - return IntPtr.Zero; - } - - private static IntPtr cs_alloc_bool(bool arg1) - { - return CSHandleContainer.GetCurrent().CreateGCHandle(arg1); - } - - private static IntPtr cs_alloc_null() - { - return IntPtr.Zero; - } - - private static IntPtr cs_create_root(IntPtr inValue) - { - object value = HandleUtils.GetObjectFromIntPtr(inValue); - GCHandle handle = GCHandle.Alloc(new CSPersistent(value)); - return GCHandle.ToIntPtr(handle); - } - - private static IntPtr cs_query_root(IntPtr inValue) - { - CSPersistent persistent = (CSPersistent)HandleUtils.GetObjectFromIntPtr(inValue); - return CSHandleContainer.GetCurrent().CreateGCHandle(persistent.Value); - } - - private static void cs_destroy_root(IntPtr inValue) - { - GCHandle handle = GCHandle.FromIntPtr(inValue); - CSPersistent persistent = (CSPersistent)handle.Target; - handle.Free(); - } - - private static void cs_val_gc(IntPtr inArg1, CSAbstract.FinalizerDelegate arg2) - { - object value = HandleUtils.GetObjectFromIntPtr(inArg1); - if (value == null) - return; - - if (value is CSAbstract) - { - CSAbstract arg1 = (CSAbstract)value; - arg1.Finalizer = arg2; - } - else - { - // TODO - } - } - - private static double cs_val_number(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return 0; - - if (arg1 is sbyte) - return (sbyte)arg1; - else if (arg1 is byte) - return (byte)arg1; - else if (arg1 is short) - return (short)arg1; - else if (arg1 is ushort) - return (ushort)arg1; - else if (arg1 is int) - return (int)arg1; - else if (arg1 is uint) - return (uint)arg1; - else if (arg1 is long) - return (long)arg1; - else if (arg1 is ulong) - return (ulong)arg1; - else if (arg1 is float) - return (float)arg1; - else if (arg1 is double) - return (double)arg1; - else if (arg1 is decimal) - { - decimal d = (decimal)(arg1); - return decimal.ToDouble(d); - } - - return 0; - } - - private static int cs_val_strlen(IntPtr inArg1) - { - String arg1 = (String)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return 0; - - return Encoding.UTF8.GetByteCount(arg1); - } - - private static IntPtr cs_val_string(IntPtr inArg1) - { - String arg1 = (String)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return IntPtr.Zero; - - CSHandleContainer container = CSHandleContainer.GetCurrent(); - byte[] bytes = System.Text.Encoding.UTF8.GetBytes(arg1); - IntPtr memory = container.AllocateMemory(sizeof(byte) * (bytes.Length + 1)); - Marshal.Copy(bytes, 0, memory, bytes.Length); - Marshal.WriteByte(memory, bytes.Length, 0); - return memory; - } - - private static int cs_val_int(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return 0; - - if (arg1 is sbyte) - return (sbyte)arg1; - else if (arg1 is byte) - return (byte)arg1; - else if (arg1 is short) - return (short)arg1; - else if (arg1 is ushort) - return (ushort)arg1; - else if (arg1 is int) - return (int)arg1; - else if (arg1 is uint) - return (int)(uint)arg1; - else if (arg1 is long) - return (int)(long)arg1; - else if (arg1 is ulong) - return (int)(ulong)arg1; - else if (arg1 is float) - return (int)(float)arg1; - else if (arg1 is double) - return (int)(double)arg1; - else if (arg1 is decimal) - { - decimal d = (decimal)arg1; - return decimal.ToInt32(d); - } - - return 0; - } - - private static IntPtr cs_alloc_int(int arg1) - { - return CSHandleContainer.GetCurrent().CreateGCHandle(arg1); - } - - private static IntPtr cs_alloc_array(int arg1) - { - return CSHandleContainer.GetCurrent().CreateGCHandle(new Array(new object[arg1])); - } - - private static IntPtr cs_alloc_array_type(int arg1, hxValueType arg2) - { - Array arr; - switch(arg2) - { - case hxValueType.valtBool: - arr = new Array(new bool[arg1]); - break; - case hxValueType.valtInt: - arr = new Array(new int[arg1]); - break; - case hxValueType.valtFloat: - arr = new Array(new double[arg1]); - break; - case hxValueType.valtString: - arr = new Array(new String[arg1]); - break; - case hxValueType.valtObject: - arr = new Array(new object[arg1]); - break; - default: - return IntPtr.Zero; - } - return CSHandleContainer.GetCurrent().CreateGCHandle(arr); - } - - private static int cs_val_array_size(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - else if (arg1 is Array) - return ((Array)arg1).length; - - return 0; - } - - private static IntPtr cs_val_array_i(IntPtr inArg1, int arg2) - { - Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return IntPtr.Zero; - - return CSHandleContainer.GetCurrent().CreateGCHandle(arg1[arg2]); - } - - private static void cs_val_array_set_i(IntPtr inArg1, int arg2, IntPtr inArg3) - { - Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1); - object arg3 = HandleUtils.GetObjectFromIntPtr(inArg3); - if (arg1 == null) - return; - - arg1[arg2] = arg3; - } - - private static void cs_val_array_push(IntPtr inArg1, IntPtr inArg2) - { - Array arg1 = (Array)HandleUtils.GetObjectFromIntPtr(inArg1); - object arg2 = HandleUtils.GetObjectFromIntPtr(inArg2); - if (arg1 == null) - return; - - arg1.push(arg2); - } - - private static int cs_val_id(String arg1) - { - return CSHandleContainer.GetCurrent().GetId(arg1); - } - - private static void cs_alloc_field(IntPtr inArg1, int arg2, IntPtr inArg3) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - object arg3 = HandleUtils.GetObjectFromIntPtr(inArg3); - if (arg1 == null) - throw new ArgumentNullException("Null object set"); - - String field = CSHandleContainer.GetCurrent().GetStringFromId(arg2); - Reflect.setField(arg1, field, arg3); - } - - private static IntPtr cs_val_field(IntPtr inArg1, int arg2) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - throw new ArgumentNullException("Null object get"); - - CSHandleContainer container = CSHandleContainer.GetCurrent(); - String field = container.GetStringFromId(arg2); - return container.CreateGCHandle(Reflect.field(arg1, field)); - } - - private static IntPtr cs_val_call0(IntPtr inArg1) - { - Function arg1 = (Function)HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - throw new ArgumentNullException("Null function call"); - - return CSHandleContainer.GetCurrent().CreateGCHandle(arg1.__hx_invoke0_o()); - } - - private static IntPtr cs_alloc_empty_object() - { - return CSHandleContainer.GetCurrent().CreateGCHandle(new DynamicObject()); - } - - private static IntPtr cs_alloc_string_len(IntPtr inStr, int inLen) - { - byte[] bytes = new byte[inLen]; - Marshal.Copy(inStr, bytes, 0, inLen); - String str = Encoding.UTF8.GetString(bytes, 0, inLen); - return CSHandleContainer.GetCurrent().CreateGCHandle(str); - } - - private static IntPtr cs_alloc_wstring_len(IntPtr inStr, int inLen) - { - byte[] bytes; - String str; - int totalLen; - switch(Environment.OSVersion.Platform) - { - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - totalLen = inLen * 2; - bytes = new byte[totalLen]; - Marshal.Copy(inStr, bytes, 0, totalLen); - str = Encoding.Unicode.GetString(bytes); - return CSHandleContainer.GetCurrent().CreateGCHandle(str); - default: - totalLen = inLen * 4; - bytes = new byte[totalLen]; - Marshal.Copy(inStr, bytes, 0, totalLen); - str = Encoding.UTF32.GetString(bytes); - return CSHandleContainer.GetCurrent().CreateGCHandle(str); - } - } - - private static IntPtr cs_alloc_float(double arg1) - { - return CSHandleContainer.GetCurrent().CreateGCHandle(arg1); - } - - private static IntPtr cs_alloc_buffer_len(int inLen) - { - byte[] buffer = new byte[inLen]; - return CSHandleContainer.GetCurrent().CreatePinnedGCHandle(buffer); - } - - private static IntPtr cs_buffer_val(IntPtr b) - { - return b; - } - - private static IntPtr cs_val_to_buffer(IntPtr arg1) - { - return arg1; - } - - private static void cs_buffer_set_size(IntPtr inBuffer, int inLen) - { - byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer); - if (buffer != null) { - System.Array.Resize(ref buffer, inLen); - } - } - - private static int cs_buffer_size(IntPtr inBuffer) - { - byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer); - if (buffer == null) - return 0; - - return buffer.Length; - } - - private static IntPtr cs_buffer_data(IntPtr inBuffer) - { - byte[] buffer = (byte[])HandleUtils.GetObjectFromIntPtr(inBuffer); - if (buffer == null) - return IntPtr.Zero; - - return CSHandleContainer.GetCurrent().GetAddrOfBlittableObject(buffer); - } - - private static IntPtr cs_pin_buffer(IntPtr inBuffer) - { - byte[] buffer = (byte[])GCHandle.FromIntPtr(inBuffer).Target; - return GCHandle.ToIntPtr(GCHandle.Alloc(buffer, GCHandleType.Pinned)); - } - - private static void cs_unpin_buffer(IntPtr inArg1) - { - GCHandle handle = GCHandle.FromIntPtr(inArg1); - handle.Free(); - } - - private static bool cs_val_bool(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - if (arg1 == null) - return false; - - return (bool)arg1; - } - - private static void cs_val_throw(IntPtr inArg1) - { - object arg1 = HandleUtils.GetObjectFromIntPtr(inArg1); - throw new Exception(arg1.ToString()); - } - - private static IntPtr cs_empty() { return IntPtr.Zero; } - - static CFFICSLoader() - { - val_type = new DelegateConverter(new ValTypeDelegate(cs_val_type)); - alloc_kind = new DelegateConverter(new AllocKindDelegate(cs_alloc_kind)); - alloc_abstract = new DelegateConverter(new AllocAbstractDelegate(cs_alloc_abstract)); - free_abstract = new DelegateConverter(new FreeAbstractDelegate(cs_free_abstract)); - val_to_kind = new DelegateConverter(new ValToKindDelegate(cs_val_to_kind)); - val_data = new DelegateConverter(new ValDataDelegate(cs_val_data)); - val_array_int = new DelegateConverter(new ValArrayIntDelegate(cs_val_array_int)); - alloc_bool = new DelegateConverter(new AllocBoolDelegate(cs_alloc_bool)); - alloc_null = new DelegateConverter(new AllocNullDelegate(cs_alloc_null)); - create_root = new DelegateConverter(new CreateRootDelegate(cs_create_root)); - query_root = new DelegateConverter(new QueryRootDelegate(cs_query_root)); - destroy_root = new DelegateConverter(new DestroyRootDelegate(cs_destroy_root)); - val_gc = new DelegateConverter(new ValGCDelegate(cs_val_gc)); - val_number = new DelegateConverter(new ValNumberDelegate(cs_val_number)); - val_strlen = new DelegateConverter(new ValStrLenDelegate(cs_val_strlen)); - val_string = new DelegateConverter(new ValStringDelegate(cs_val_string)); - val_int = new DelegateConverter(new ValIntDelegate(cs_val_int)); - alloc_int = new DelegateConverter(new AllocIntDelegate(cs_alloc_int)); - alloc_array = new DelegateConverter(new AllocArrayDelegate(cs_alloc_array)); - alloc_array_type = new DelegateConverter(new AllocArrayTypeDelegate(cs_alloc_array_type)); - val_array_size = new DelegateConverter(new ValArraySizeDelegate(cs_val_array_size)); - val_array_i = new DelegateConverter(new ValArrayIDelegate(cs_val_array_i)); - val_array_set_i = new DelegateConverter(new ValArraySetIDelegate(cs_val_array_set_i)); - val_array_push = new DelegateConverter(new ValArrayPushDelegate(cs_val_array_push)); - val_id = new DelegateConverter(new ValIdDelegate(cs_val_id)); - alloc_field = new DelegateConverter(new AllocFieldDelegate(cs_alloc_field)); - val_call0 = new DelegateConverter(new ValCall0Delegate(cs_val_call0)); - alloc_empty_object = new DelegateConverter(new AllocEmptyObjectDelegate(cs_alloc_empty_object)); - alloc_string_len = new DelegateConverter(new AllocStringLenDelegate(cs_alloc_string_len)); - alloc_wstring_len = new DelegateConverter(new AllocWStringLenDelegate(cs_alloc_wstring_len)); - alloc_float = new DelegateConverter(new AllocFloatDelegate(cs_alloc_float)); - alloc_buffer_len = new DelegateConverter(new AllocBufferLenDelegate(cs_alloc_buffer_len)); - buffer_data = new DelegateConverter(new BufferDataDelegate(cs_buffer_data)); - buffer_val = new DelegateConverter(new BufferValDelegate(cs_buffer_val)); - val_to_buffer = new DelegateConverter(new ValToBufferDelegate(cs_val_to_buffer)); - buffer_set_size = new DelegateConverter(new BufferSetSizeDelegate(cs_buffer_set_size)); - buffer_size = new DelegateConverter(new BufferSizeDelegate(cs_buffer_size)); - pin_buffer = new DelegateConverter(new PinBufferDelegate(cs_pin_buffer)); - unpin_buffer = new DelegateConverter(new UnPinBufferDelegate(cs_unpin_buffer)); - val_field = new DelegateConverter(new ValFieldDelegate(cs_val_field)); - val_bool = new DelegateConverter(new ValBoolDelegate(cs_val_bool)); - val_throw = new DelegateConverter(new ValThrowDelegate(cs_val_throw)); - empty = new DelegateConverter(new EmptyDelegate(cs_empty)); - } - - internal static IntPtr Load(String inName) - { - switch (inName) - { - case "val_type": - return val_type.ToPointer(); - case "alloc_kind": - return alloc_kind.ToPointer(); - case "alloc_abstract": - return alloc_abstract.ToPointer(); - case "free_abstract": - return free_abstract.ToPointer(); - case "val_to_kind": - return val_to_kind.ToPointer(); - case "val_array_int": - return val_array_int.ToPointer(); - case "alloc_bool": - return alloc_bool.ToPointer(); - case "alloc_null": - return alloc_null.ToPointer(); - case "create_root": - return create_root.ToPointer(); - case "query_root": - return query_root.ToPointer(); - case "destroy_root": - return destroy_root.ToPointer(); - case "val_data": - return val_data.ToPointer(); - case "alloc_root": - return empty.ToPointer(); - case "val_gc": - return val_gc.ToPointer(); - case "val_number": - return val_number.ToPointer(); - case "val_strlen": - return val_strlen.ToPointer(); - case "val_string": - return val_string.ToPointer(); - case "val_int": - return val_int.ToPointer(); - case "alloc_int": - return alloc_int.ToPointer(); - case "alloc_array": - return alloc_array.ToPointer(); - case "alloc_array_type": - return alloc_array_type.ToPointer(); - case "val_array_size": - return val_array_size.ToPointer(); - case "val_array_i": - return val_array_i.ToPointer(); - case "val_array_set_i": - return val_array_set_i.ToPointer(); - case "val_array_push": - return val_array_push.ToPointer(); - case "val_id": - return val_id.ToPointer(); - case "alloc_field": - return alloc_field.ToPointer(); - case "val_call0": - return val_call0.ToPointer(); - case "alloc_empty_object": - return alloc_empty_object.ToPointer(); - case "alloc_string_len": - return alloc_string_len.ToPointer(); - case "alloc_wstring_len": - return alloc_wstring_len.ToPointer(); - case "alloc_float": - return alloc_float.ToPointer(); - case "alloc_buffer_len": - return alloc_buffer_len.ToPointer(); - case "buffer_data": - return buffer_data.ToPointer(); - case "buffer_val": - return buffer_val.ToPointer(); - case "val_to_buffer": - return val_to_buffer.ToPointer(); - case "buffer_set_size": - return buffer_set_size.ToPointer(); - case "buffer_size": - return buffer_size.ToPointer(); - case "pin_buffer": - return pin_buffer.ToPointer(); - case "unpin_buffer": - return unpin_buffer.ToPointer(); - case "val_field": - return val_field.ToPointer(); - case "val_bool": - return val_bool.ToPointer(); - case "val_throw": - return val_throw.ToPointer(); - } - - return IntPtr.Zero; - } - } -} diff --git a/templates/cs/src/cs/ndll/CSAbstract.cs b/templates/cs/src/cs/ndll/CSAbstract.cs deleted file mode 100644 index f9cb73bf41..0000000000 --- a/templates/cs/src/cs/ndll/CSAbstract.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class CSAbstract : IDisposable - { - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - internal delegate IntPtr FinalizerDelegate(IntPtr arg1); - - internal IntPtr Pointer { get; private set; } - internal int Kind { get; private set; } - private FinalizerDelegate finalizer; - internal FinalizerDelegate Finalizer - { - get - { - return finalizer; - } - set - { - if (disposed && value != null) - throw new InvalidOperationException("Tried to set finalizer to disposed CSAbstract"); - if (finalizer != null && value != null) - throw new InvalidOperationException("Finalizer is already set"); - - finalizer = value; - if (finalizer == null) - { - GC.SuppressFinalize(this); - disposed = true; - } - } - } - private bool disposed; - - internal CSAbstract(int kind, IntPtr ptr) - { - Pointer = ptr; - Kind = kind; - disposed = false; - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposed) - return; - disposed = true; - if (finalizer == null) - return; - - GCHandle handle = GCHandle.Alloc(this, GCHandleType.Normal); - finalizer(GCHandle.ToIntPtr(handle)); - handle.Free(); - } - - public void Free() - { - Pointer = IntPtr.Zero; - finalizer = null; - disposed = true; - GC.SuppressFinalize(this); - } - - ~CSAbstract() - { - Dispose(false); - } - } -} \ No newline at end of file diff --git a/templates/cs/src/cs/ndll/CSHandleContainer.cs b/templates/cs/src/cs/ndll/CSHandleContainer.cs deleted file mode 100644 index 0393a1af36..0000000000 --- a/templates/cs/src/cs/ndll/CSHandleContainer.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class CSHandleContainer : IDisposable - { - private bool disposed = false; - private System.Collections.Generic.Dictionary sgNameToID; - private System.Collections.Generic.List sgIDToName; - - internal System.Collections.Generic.List handles; - internal System.Collections.Generic.List memoryList; - - private static CSHandleContainer container; - - private CSHandleContainer() - { - sgNameToID = new System.Collections.Generic.Dictionary(); - sgIDToName = new System.Collections.Generic.List(); - - handles = new System.Collections.Generic.List(); - memoryList = new System.Collections.Generic.List(); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposed) - return; - - for (int i = 0; i < handles.Count; ++i) - handles[i].Free(); - - for (int i = 0; i < memoryList.Count; ++i) - Marshal.FreeHGlobal(memoryList[i]); - - disposed = true; - } - - ~CSHandleContainer() - { - Dispose(false); - } - - internal int GetId(string key) - { - if (sgNameToID.ContainsKey(key)) - return sgNameToID[key]; - int idx = sgIDToName.Count; - sgIDToName.Add(key); - sgNameToID.Add(key, idx); - return idx; - } - - internal string GetStringFromId(int id) - { - return sgIDToName[id]; - } - - internal IntPtr CreateGCHandle(Object value) - { - handles.Add(GCHandle.Alloc(value, GCHandleType.Normal)); - return GCHandle.ToIntPtr(handles[handles.Count - 1]); - } - - internal IntPtr CreatePinnedGCHandle(Object value) - { - handles.Add(GCHandle.Alloc(value, GCHandleType.Pinned)); - return GCHandle.ToIntPtr(handles[handles.Count - 1]); - } - - internal IntPtr GetAddrOfBlittableObject(Object value) - { - handles.Add(GCHandle.Alloc(value, GCHandleType.Pinned)); - return handles[handles.Count - 1].AddrOfPinnedObject(); - } - - internal IntPtr AllocateMemory(int length) - { - IntPtr memory = Marshal.AllocHGlobal(length); - memoryList.Add(memory); - return memory; - } - - internal void ResizeHandles(int handleSize, int memoryListSize) - { - int oldHandleSize = handles.Count; - for (int i = handleSize; i < oldHandleSize; ++i) - { - handles[i].Free(); - } - handles.RemoveRange(handleSize, oldHandleSize - handleSize); - - int oldMemoryListSize = memoryList.Count; - for (int i = memoryListSize; i < oldMemoryListSize; ++i) - Marshal.FreeHGlobal(memoryList[i]); - memoryList.RemoveRange(memoryListSize, oldMemoryListSize - memoryListSize); - } - - internal static CSHandleContainer GetCurrent() - { - if (container == null) - container = new CSHandleContainer(); - - return container; - } - - } -} diff --git a/templates/cs/src/cs/ndll/CSHandleScope.cs b/templates/cs/src/cs/ndll/CSHandleScope.cs deleted file mode 100644 index 9afd5dfa8b..0000000000 --- a/templates/cs/src/cs/ndll/CSHandleScope.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace cs.ndll -{ - struct CSHandleScope - { - internal static CSHandleScope Create() - { - CSHandleScope scope = new CSHandleScope(); - CSHandleContainer container = CSHandleContainer.GetCurrent(); - scope.handleIndex = container.handles.Count; - scope.memoryListIndex = container.memoryList.Count; - return scope; - } - - internal void Destroy() - { - CSHandleContainer.GetCurrent().ResizeHandles(handleIndex, memoryListIndex); - } - - private int handleIndex; - private int memoryListIndex; - }; -} \ No newline at end of file diff --git a/templates/cs/src/cs/ndll/CSPersistent.cs b/templates/cs/src/cs/ndll/CSPersistent.cs deleted file mode 100644 index e92b879361..0000000000 --- a/templates/cs/src/cs/ndll/CSPersistent.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class CSPersistent - { - internal object Value { get; private set; } - - internal CSPersistent(object value) - { - Value = value; - } - - internal void Destroy() - { - Value = null; - } - } -} diff --git a/templates/cs/src/cs/ndll/DelegateConverter.cs b/templates/cs/src/cs/ndll/DelegateConverter.cs deleted file mode 100644 index 08cc862d6e..0000000000 --- a/templates/cs/src/cs/ndll/DelegateConverter.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class DelegateConverter : IDisposable - { - private T func; - private IntPtr funcPtr; - private GCHandle handle; - - internal DelegateConverter(T func) - { - this.func = func; - } - - ~DelegateConverter() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (!handle.IsAllocated) - return; - - handle.Free(); - } - - internal IntPtr ToPointer() - { - if (!handle.IsAllocated) - { - funcPtr = Marshal.GetFunctionPointerForDelegate(func as Delegate); - handle = GCHandle.Alloc(funcPtr, GCHandleType.Pinned); - } - return (IntPtr)handle.Target; - } - } -} \ No newline at end of file diff --git a/templates/cs/src/cs/ndll/HandleUtils.cs b/templates/cs/src/cs/ndll/HandleUtils.cs deleted file mode 100644 index 99419f708f..0000000000 --- a/templates/cs/src/cs/ndll/HandleUtils.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class HandleUtils - { - internal static bool IsEmpty(GCHandle handle) - { - if (handle == null) - return true; - else if (handle.Target == null) - return true; - - return false; - } - - internal static object GetObjectFromIntPtr(IntPtr ptr) - { - if (ptr == IntPtr.Zero) - return null; - - return GCHandle.FromIntPtr(ptr).Target; - } - } -} diff --git a/templates/cs/src/cs/ndll/NDLLFunction.cs b/templates/cs/src/cs/ndll/NDLLFunction.cs deleted file mode 100644 index 95ae3e9b42..0000000000 --- a/templates/cs/src/cs/ndll/NDLLFunction.cs +++ /dev/null @@ -1,272 +0,0 @@ -using System; -using System.IO; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - public class NDLLFunction : IDisposable - { - private IntPtr module; - private Delegate func; - private int numArgs; - private static CFFICSLoader.CFFILoaderDelegate loaderDelegate; - private static GCHandle pinnedLoaderFunc; - public static String LibraryDir = null; - public static String LibraryPrefix = ""; - public static String LibrarySuffix = ".ndll"; - - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr NDLLFunctionDelegate(); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate void HxSetLoaderDelegate(IntPtr loader); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr CallMultDelegate(IntPtr args); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call0Delegate(); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call1Delegate(IntPtr arg1); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call2Delegate(IntPtr arg1, IntPtr arg2); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call3Delegate(IntPtr arg1, IntPtr arg2, IntPtr arg3); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call4Delegate(IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4); - [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] - private delegate IntPtr Call5Delegate(IntPtr arg1, IntPtr arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5); - - NDLLFunction(IntPtr module, Delegate func, int numArgs) - { - this.module = module; - this.func = func; - this.numArgs = numArgs; - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (module != IntPtr.Zero) - { - NativeMethods.FreeLibraryWrap(module); - module = IntPtr.Zero; - } - } - - ~NDLLFunction() - { - Dispose(false); - } - - public static NDLLFunction Load(String lib, String name, int numArgs) - { - if (numArgs < -1 || numArgs > 5) - throw new ArgumentOutOfRangeException("Invalid numArgs: " + numArgs); - - IntPtr module = IntPtr.Zero; - try - { - if (LibraryDir != null && (lib.StartsWith("./") || lib.StartsWith(".\\"))) - lib = LibraryDir + Path.DirectorySeparatorChar + LibraryPrefix + lib.Substring(2) + LibrarySuffix; - else - lib = lib + LibrarySuffix; - module = NativeMethods.LoadLibraryWrap(lib); - if (module == IntPtr.Zero) - return null; - - String funcName; - if (numArgs != -1) - funcName = String.Format("{0}__{1}", name, numArgs); - else - funcName = String.Format("{0}__MULT", name); - - IntPtr funcPtr = NativeMethods.GetProcAddressWrap(module, funcName); - if (funcPtr == IntPtr.Zero) - return null; - NDLLFunctionDelegate func = (NDLLFunctionDelegate)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(NDLLFunctionDelegate)); - Delegate cfunc = null; - switch (numArgs) - { - case -1: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(CallMultDelegate)); - break; - case 0: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call0Delegate)); - break; - case 1: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call1Delegate)); - break; - case 2: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call2Delegate)); - break; - case 3: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call3Delegate)); - break; - case 4: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call4Delegate)); - break; - case 5: - cfunc = Marshal.GetDelegateForFunctionPointer(func(), typeof(Call5Delegate)); - break; - } - - IntPtr dll_hx_set_loader_ptr = NativeMethods.GetProcAddressWrap(module, "hx_set_loader"); - if (dll_hx_set_loader_ptr == IntPtr.Zero) - return null; - HxSetLoaderDelegate dll_hx_set_loader = (HxSetLoaderDelegate)Marshal.GetDelegateForFunctionPointer(dll_hx_set_loader_ptr, typeof(HxSetLoaderDelegate)); - IntPtr callbackPtr; - if (loaderDelegate == null) - { - loaderDelegate = new CFFICSLoader.CFFILoaderDelegate(CFFICSLoader.Load); - callbackPtr = Marshal.GetFunctionPointerForDelegate(loaderDelegate); - pinnedLoaderFunc = GCHandle.Alloc(callbackPtr, GCHandleType.Pinned); - } - else - { - callbackPtr = (IntPtr)pinnedLoaderFunc.Target; - } - - dll_hx_set_loader(callbackPtr); - - NDLLFunction ndllFunc = new NDLLFunction(module, cfunc, numArgs); - module = IntPtr.Zero; - return ndllFunc; - } - finally - { - if (module != IntPtr.Zero) - NativeMethods.FreeLibraryWrap(module); - } - } - - public object CallMult(Array args) - { - if (numArgs != -1) - throw new InvalidOperationException(); - - Array hxArray = (Array)args; - CSHandleScope scope = CSHandleScope.Create(); - GCHandle[] handles = new GCHandle[hxArray.length]; - for (int i = 0; i < hxArray.length; ++i) - handles[i] = GCHandle.Alloc(hxArray[i]); - IntPtr[] pointers = new IntPtr[hxArray.length]; - for (int i = 0; i < hxArray.length; ++i) - pointers[i] = GCHandle.ToIntPtr(handles[i]); - GCHandle pinnedArray = GCHandle.Alloc(pointers, GCHandleType.Pinned); - - CallMultDelegate cfunc = (CallMultDelegate)func; - object result = HandleUtils.GetObjectFromIntPtr(cfunc(pinnedArray.AddrOfPinnedObject())); - scope.Destroy(); - for (int i = 0; i < hxArray.length; ++i) - handles[i].Free(); - pinnedArray.Free(); - return result; - } - - public object Call0() - { - if (numArgs != 0) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call0Delegate cfunc = (Call0Delegate)func; - object result = HandleUtils.GetObjectFromIntPtr(cfunc()); - scope.Destroy(); - return result; - } - - public object Call1(object arg1) - { - if (numArgs != 1) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call1Delegate cfunc = (Call1Delegate)func; - GCHandle gch1 = GCHandle.Alloc(arg1); - object result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1))); - scope.Destroy(); - gch1.Free(); - return result; - } - - public object Call2(object arg1, object arg2) - { - if (numArgs != 2) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call2Delegate cfunc = (Call2Delegate)func; - GCHandle gch1 = GCHandle.Alloc(arg1); - GCHandle gch2 = GCHandle.Alloc(arg2); - object result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1), GCHandle.ToIntPtr(gch2))); - scope.Destroy(); - gch1.Free(); - gch2.Free(); - return result; - } - - public object Call3(object arg1, object arg2, object arg3) - { - if (numArgs != 3) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call3Delegate cfunc = (Call3Delegate)func; - GCHandle gch1 = GCHandle.Alloc(arg1); - GCHandle gch2 = GCHandle.Alloc(arg2); - GCHandle gch3 = GCHandle.Alloc(arg3); - object result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1), GCHandle.ToIntPtr(gch2), GCHandle.ToIntPtr(gch3))); - scope.Destroy(); - gch1.Free(); - gch2.Free(); - gch3.Free(); - return result; - } - - public object Call4(Object arg1, Object arg2, Object arg3, Object arg4) - { - if (numArgs != 4) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call4Delegate cfunc = (Call4Delegate)func; - GCHandle gch1 = GCHandle.Alloc(arg1); - GCHandle gch2 = GCHandle.Alloc(arg2); - GCHandle gch3 = GCHandle.Alloc(arg3); - GCHandle gch4 = GCHandle.Alloc(arg4); - object result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1), GCHandle.ToIntPtr(gch2), GCHandle.ToIntPtr(gch3), GCHandle.ToIntPtr(gch4))); - scope.Destroy(); - gch1.Free(); - gch2.Free(); - gch3.Free(); - gch4.Free(); - return result; - } - - public Object Call5(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) - { - if (numArgs != 5) - throw new InvalidOperationException(); - - CSHandleScope scope = CSHandleScope.Create(); - Call5Delegate cfunc = (Call5Delegate)func; - GCHandle gch1 = GCHandle.Alloc(arg1); - GCHandle gch2 = GCHandle.Alloc(arg2); - GCHandle gch3 = GCHandle.Alloc(arg3); - GCHandle gch4 = GCHandle.Alloc(arg4); - GCHandle gch5 = GCHandle.Alloc(arg5); - object result = HandleUtils.GetObjectFromIntPtr(cfunc(GCHandle.ToIntPtr(gch1), - GCHandle.ToIntPtr(gch2), GCHandle.ToIntPtr(gch3), GCHandle.ToIntPtr(gch4), GCHandle.ToIntPtr(gch5))); - scope.Destroy(); - gch1.Free(); - gch2.Free(); - gch3.Free(); - gch4.Free(); - gch5.Free(); - return result; - } - } -} diff --git a/templates/cs/src/cs/ndll/NativeMethods.cs b/templates/cs/src/cs/ndll/NativeMethods.cs deleted file mode 100644 index 2bd3b5ad64..0000000000 --- a/templates/cs/src/cs/ndll/NativeMethods.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace cs.ndll -{ - class NativeMethods - { - public static IntPtr LoadLibraryWrap(String filename) - { - switch(Environment.OSVersion.Platform) - { - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - return LoadLibrary(filename); - default: - return dlopen(filename, RTLD_NOW); - } - } - - public static void FreeLibraryWrap(IntPtr handle) - { - switch(Environment.OSVersion.Platform) - { - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - FreeLibrary(handle); - break; - default: - dlclose(handle); - break; - } - } - - public static IntPtr GetProcAddressWrap(IntPtr handle, String symbol) - { - switch(Environment.OSVersion.Platform) - { - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - return GetProcAddress(handle, symbol); - default: - return dlsym(handle, symbol); - } - } - - internal const int RTLD_NOW = 2; - - [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] - private static extern IntPtr LoadLibrary(String lpFileName); - [DllImport("kernel32", SetLastError = true)] - private static extern bool FreeLibrary(IntPtr hModule); - [DllImport("kernel32", SetLastError = true, ExactSpelling = false, BestFitMapping = false, ThrowOnUnmappableChar = true)] - private static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)]String lpProcName); - [DllImport("dl", BestFitMapping = false, ThrowOnUnmappableChar = true)] - private static extern IntPtr dlopen([MarshalAs(UnmanagedType.LPTStr)]String filename, int flags); - [DllImport("dl")] - private static extern int dlclose(IntPtr handle); - [DllImport("dl", BestFitMapping = false, ThrowOnUnmappableChar = true)] - private static extern IntPtr dlsym(IntPtr handle, [MarshalAs(UnmanagedType.LPTStr)] String symbol); - } -} diff --git a/templates/extension/project/Build.xml b/templates/extension/project/Build.xml index 52425bbb62..ae9d18543d 100644 --- a/templates/extension/project/Build.xml +++ b/templates/extension/project/Build.xml @@ -1,34 +1,33 @@ - + - + - + - + - + - + - - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/templates/haxe/ApplicationMain.hx b/templates/haxe/ApplicationMain.hx index 0c6a0a495f..05b3d5409b 100644 --- a/templates/haxe/ApplicationMain.hx +++ b/templates/haxe/ApplicationMain.hx @@ -134,7 +134,7 @@ import ::APP_MAIN::; var result = app.exec(); - #if (sys && !ios && !nodejs && !webassembly) + #if (sys && !ios && !webassembly) lime.system.System.exit(result); #end @@ -144,46 +144,4 @@ import ::APP_MAIN::; #end } - - @:noCompletion @:dox(hide) public static function __init__() - { - var init = lime.app.Application; - - #if neko - // Copy from https://github.com/HaxeFoundation/haxe/blob/development/std/neko/_std/Sys.hx#L164 - // since Sys.programPath () isn't available in __init__ - var sys_program_path = - { - var m = neko.vm.Module.local().name; - try - { - sys.FileSystem.fullPath(m); - } - catch (e:Dynamic) - { - // maybe the neko module name was supplied without .n extension... - if (!StringTools.endsWith(m, ".n")) - { - try - { - sys.FileSystem.fullPath(m + ".n"); - } - catch (e:Dynamic) - { - m; - } - } - else - { - m; - } - } - }; - - var loader = new neko.vm.Loader(untyped $loader); - loader.addPath(haxe.io.Path.directory(#if (haxe_ver >= 3.3) sys_program_path #else Sys.executablePath() #end)); - loader.addPath("./"); - loader.addPath("@executable_path/"); - #end - } } diff --git a/templates/java/hxml/debug.hxml b/templates/java/hxml/debug.hxml deleted file mode 100644 index 07c8109106..0000000000 --- a/templates/java/hxml/debug.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --java ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") --debug \ No newline at end of file diff --git a/templates/java/hxml/final.hxml b/templates/java/hxml/final.hxml deleted file mode 100644 index b6dee86e7f..0000000000 --- a/templates/java/hxml/final.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --java ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") --D final \ No newline at end of file diff --git a/templates/java/hxml/release.hxml b/templates/java/hxml/release.hxml deleted file mode 100644 index 50eea373cb..0000000000 --- a/templates/java/hxml/release.hxml +++ /dev/null @@ -1,4 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --java ::OUTPUT_DIR::/obj ---macro keep("::APP_MAIN::") \ No newline at end of file diff --git a/templates/java/lib/disruptor.jar b/templates/java/lib/disruptor.jar deleted file mode 100755 index 6f88adacd6..0000000000 Binary files a/templates/java/lib/disruptor.jar and /dev/null differ diff --git a/templates/java/lib/lwjgl.jar b/templates/java/lib/lwjgl.jar deleted file mode 100755 index b879edc17b..0000000000 Binary files a/templates/java/lib/lwjgl.jar and /dev/null differ diff --git a/templates/java/ndll/Linux/liblwjgl.so b/templates/java/ndll/Linux/liblwjgl.so deleted file mode 100755 index b7d02f9f9b..0000000000 Binary files a/templates/java/ndll/Linux/liblwjgl.so and /dev/null differ diff --git a/templates/java/ndll/Linux/libopenal.so b/templates/java/ndll/Linux/libopenal.so deleted file mode 100755 index 7fd175496e..0000000000 Binary files a/templates/java/ndll/Linux/libopenal.so and /dev/null differ diff --git a/templates/java/ndll/Linux64/liblwjgl.so b/templates/java/ndll/Linux64/liblwjgl.so deleted file mode 100755 index acf05a0520..0000000000 Binary files a/templates/java/ndll/Linux64/liblwjgl.so and /dev/null differ diff --git a/templates/java/ndll/Linux64/libopenal.so b/templates/java/ndll/Linux64/libopenal.so deleted file mode 100755 index 7fd175496e..0000000000 Binary files a/templates/java/ndll/Linux64/libopenal.so and /dev/null differ diff --git a/templates/java/ndll/Mac64/liblwjgl.dylib b/templates/java/ndll/Mac64/liblwjgl.dylib deleted file mode 100755 index 80951fa46f..0000000000 Binary files a/templates/java/ndll/Mac64/liblwjgl.dylib and /dev/null differ diff --git a/templates/java/ndll/Mac64/libopenal.dylib b/templates/java/ndll/Mac64/libopenal.dylib deleted file mode 100755 index 7a5913868d..0000000000 Binary files a/templates/java/ndll/Mac64/libopenal.dylib and /dev/null differ diff --git a/templates/java/ndll/Windows/OpenAL32.dll b/templates/java/ndll/Windows/OpenAL32.dll deleted file mode 100755 index 68cd4ee456..0000000000 Binary files a/templates/java/ndll/Windows/OpenAL32.dll and /dev/null differ diff --git a/templates/java/ndll/Windows/lwjgl.dll b/templates/java/ndll/Windows/lwjgl.dll deleted file mode 100755 index 4615b4570d..0000000000 Binary files a/templates/java/ndll/Windows/lwjgl.dll and /dev/null differ diff --git a/templates/neko/hxml/debug.hxml b/templates/neko/hxml/debug.hxml deleted file mode 100644 index 191ef100fd..0000000000 --- a/templates/neko/hxml/debug.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --neko ::NEKO_FILE:: ---macro keep("::APP_MAIN::") --debug \ No newline at end of file diff --git a/templates/neko/hxml/final.hxml b/templates/neko/hxml/final.hxml deleted file mode 100644 index b4a0c5f6ad..0000000000 --- a/templates/neko/hxml/final.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --neko ::NEKO_FILE:: ---macro keep("::APP_MAIN::") --D final \ No newline at end of file diff --git a/templates/neko/hxml/release.hxml b/templates/neko/hxml/release.hxml deleted file mode 100644 index 76812e47a3..0000000000 --- a/templates/neko/hxml/release.hxml +++ /dev/null @@ -1,4 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --neko ::NEKO_FILE:: ---macro keep("::APP_MAIN::") \ No newline at end of file diff --git a/templates/nodejs/hxml/debug.hxml b/templates/nodejs/hxml/debug.hxml deleted file mode 100644 index f0112a2669..0000000000 --- a/templates/nodejs/hxml/debug.hxml +++ /dev/null @@ -1,8 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::NODE_FILE:: --cp ::OUTPUT_DIR::/haxe ---macro allowPackage("flash") ---macro define("sys") --D nodejs --D js-flatten --debug \ No newline at end of file diff --git a/templates/nodejs/hxml/final.hxml b/templates/nodejs/hxml/final.hxml deleted file mode 100644 index 8e09552fec..0000000000 --- a/templates/nodejs/hxml/final.hxml +++ /dev/null @@ -1,8 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::NODE_FILE:: --cp ::OUTPUT_DIR::/haxe ---macro allowPackage("flash") ---macro define("sys") --D nodejs --D js-flatten --D final \ No newline at end of file diff --git a/templates/nodejs/hxml/release.hxml b/templates/nodejs/hxml/release.hxml deleted file mode 100644 index 8370ec862c..0000000000 --- a/templates/nodejs/hxml/release.hxml +++ /dev/null @@ -1,7 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::NODE_FILE:: --cp ::OUTPUT_DIR::/haxe ---macro allowPackage("flash") ---macro define("sys") --D nodejs --D js-flatten \ No newline at end of file diff --git a/templates/tizen/hxml/debug.hxml b/templates/tizen/hxml/debug.hxml deleted file mode 100644 index 3bb2d7d0d1..0000000000 --- a/templates/tizen/hxml/debug.hxml +++ /dev/null @@ -1,7 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D tizen --debug --D no-compilation \ No newline at end of file diff --git a/templates/tizen/hxml/final.hxml b/templates/tizen/hxml/final.hxml deleted file mode 100644 index 953f7d73ba..0000000000 --- a/templates/tizen/hxml/final.hxml +++ /dev/null @@ -1,7 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D tizen --D no-compilation --D final \ No newline at end of file diff --git a/templates/tizen/hxml/release.hxml b/templates/tizen/hxml/release.hxml deleted file mode 100644 index f091a281c3..0000000000 --- a/templates/tizen/hxml/release.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D tizen --D no-compilation \ No newline at end of file diff --git a/templates/tizen/template/CommandLineBuild/build_data b/templates/tizen/template/CommandLineBuild/build_data deleted file mode 100644 index 17f1fc3564..0000000000 --- a/templates/tizen/template/CommandLineBuild/build_data +++ /dev/null @@ -1,4 +0,0 @@ -PLATFORM_VER:Tizen 2.2 -ARCHITECTURE:::if (SIMULATOR)::i386::else::armel::end:: -TOOLCHAIN:GCC-4.5 -TYPE:app diff --git a/templates/tizen/template/manifest.xml b/templates/tizen/template/manifest.xml deleted file mode 100644 index 8c97989eac..0000000000 --- a/templates/tizen/template/manifest.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - ::APP_PACKAGE:: - ::APP_VERSION:: - C++App - - true - true - - - 2.2 - - http://tizen.org/privilege/application.launch - - - - - - ::APP_TITLE:: - - - mainmenu.png - - - - - diff --git a/templates/webos/hxml/debug.hxml b/templates/webos/hxml/debug.hxml deleted file mode 100644 index 10fd15e7b7..0000000000 --- a/templates/webos/hxml/debug.hxml +++ /dev/null @@ -1,8 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D webos --D HXCPP_LOAD_DEBUG --D HXCPP_RTLD_LAZY --debug \ No newline at end of file diff --git a/templates/webos/hxml/final.hxml b/templates/webos/hxml/final.hxml deleted file mode 100644 index c982bf7c32..0000000000 --- a/templates/webos/hxml/final.hxml +++ /dev/null @@ -1,7 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D webos --D HXCPP_RTLD_LAZY --D final \ No newline at end of file diff --git a/templates/webos/hxml/release.hxml b/templates/webos/hxml/release.hxml deleted file mode 100644 index 1c58b40155..0000000000 --- a/templates/webos/hxml/release.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D webos --D HXCPP_RTLD_LAZY \ No newline at end of file diff --git a/templates/webos/template/appinfo.json b/templates/webos/template/appinfo.json deleted file mode 100644 index 8cce7a7e57..0000000000 --- a/templates/webos/template/appinfo.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "title": "::APP_TITLE::", - "id": "::APP_PACKAGE::", - "type": "pdk", - "version": "::APP_VERSION::", - "vendor": "::APP_COMPANY::", - "icon": "::APP_ICON::", - "main": "::APP_FILE::", - "requiredMemory": 40 -} diff --git a/templates/webos/template/package.properties b/templates/webos/template/package.properties deleted file mode 100644 index 7e64b8c110..0000000000 --- a/templates/webos/template/package.properties +++ /dev/null @@ -1 +0,0 @@ -filemode.755=::APP_FILE:: diff --git a/templates/winjs/hxml/debug.hxml b/templates/winjs/hxml/debug.hxml deleted file mode 100644 index b887ec5c1b..0000000000 --- a/templates/winjs/hxml/debug.hxml +++ /dev/null @@ -1,9 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::OUTPUT_FILE:: --cp ::OUTPUT_DIR::/haxe --D html5 --D html --D windows --D winjs --D uwp --debug diff --git a/templates/winjs/hxml/final.hxml b/templates/winjs/hxml/final.hxml deleted file mode 100644 index 9c8a928bf3..0000000000 --- a/templates/winjs/hxml/final.hxml +++ /dev/null @@ -1,11 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::OUTPUT_FILE:: --cp ::OUTPUT_DIR::/haxe --D html5 --D html --D windows --D winjs --D uwp --D final --D js-flatten --dce full \ No newline at end of file diff --git a/templates/winjs/hxml/release.hxml b/templates/winjs/hxml/release.hxml deleted file mode 100644 index 9c63095f92..0000000000 --- a/templates/winjs/hxml/release.hxml +++ /dev/null @@ -1,8 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --js ::OUTPUT_FILE:: --cp ::OUTPUT_DIR::/haxe --D html5 --D html --D windows --D winjs --D uwp \ No newline at end of file diff --git a/templates/winjs/template/PowerShell_Set_Unrestricted.reg b/templates/winjs/template/PowerShell_Set_Unrestricted.reg deleted file mode 100644 index cc9482def0..0000000000 --- a/templates/winjs/template/PowerShell_Set_Unrestricted.reg +++ /dev/null @@ -1,6 +0,0 @@ -Windows Registry Editor Version 5.00 - -[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell] -"Path"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -"ExecutionPolicy"="Unrestricted" - diff --git a/templates/winjs/template/source/css/default.css b/templates/winjs/template/source/css/default.css deleted file mode 100644 index 74e87ccaaa..0000000000 --- a/templates/winjs/template/source/css/default.css +++ /dev/null @@ -1,5 +0,0 @@ -body { - /* Uncomment this to enable scrolling and zooming - touch-action: manipulation; - */ -} diff --git a/templates/winjs/template/source/images/LockScreenLogo.scale-200.png b/templates/winjs/template/source/images/LockScreenLogo.scale-200.png deleted file mode 100644 index 735f57adb5..0000000000 Binary files a/templates/winjs/template/source/images/LockScreenLogo.scale-200.png and /dev/null differ diff --git a/templates/winjs/template/source/images/SplashScreen.scale-200.png b/templates/winjs/template/source/images/SplashScreen.scale-200.png deleted file mode 100644 index 023e7f1fed..0000000000 Binary files a/templates/winjs/template/source/images/SplashScreen.scale-200.png and /dev/null differ diff --git a/templates/winjs/template/source/images/Square150x150Logo.scale-200.png b/templates/winjs/template/source/images/Square150x150Logo.scale-200.png deleted file mode 100644 index af49fec1a5..0000000000 Binary files a/templates/winjs/template/source/images/Square150x150Logo.scale-200.png and /dev/null differ diff --git a/templates/winjs/template/source/images/Square44x44Logo.scale-200.png b/templates/winjs/template/source/images/Square44x44Logo.scale-200.png deleted file mode 100644 index ce342a2ec8..0000000000 Binary files a/templates/winjs/template/source/images/Square44x44Logo.scale-200.png and /dev/null differ diff --git a/templates/winjs/template/source/images/Square44x44Logo.targetsize-24_altform-unplated.png b/templates/winjs/template/source/images/Square44x44Logo.targetsize-24_altform-unplated.png deleted file mode 100644 index f6c02ce97e..0000000000 Binary files a/templates/winjs/template/source/images/Square44x44Logo.targetsize-24_altform-unplated.png and /dev/null differ diff --git a/templates/winjs/template/source/images/StoreLogo.png b/templates/winjs/template/source/images/StoreLogo.png deleted file mode 100644 index 7385b56c0e..0000000000 Binary files a/templates/winjs/template/source/images/StoreLogo.png and /dev/null differ diff --git a/templates/winjs/template/source/images/Wide310x150Logo.scale-200.png b/templates/winjs/template/source/images/Wide310x150Logo.scale-200.png deleted file mode 100644 index 288995b397..0000000000 Binary files a/templates/winjs/template/source/images/Wide310x150Logo.scale-200.png and /dev/null differ diff --git a/templates/winjs/template/source/index.html b/templates/winjs/template/source/index.html deleted file mode 100644 index 59e4125e85..0000000000 --- a/templates/winjs/template/source/index.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - ::APP_TITLE:: - ::guid:: - - - - ::if favicons::::foreach (favicons):: - ::end::::end:: - - ::if linkedLibraries::::foreach (linkedLibraries):: - ::end::::end:: - - - - - - - - - - - - ::foreach assets::::if (type == "font"):: - ::end::::end:: - -
- - - - diff --git a/templates/winjs/template/source/js/main.js b/templates/winjs/template/source/js/main.js deleted file mode 100644 index ae0bd3dfc8..0000000000 --- a/templates/winjs/template/source/js/main.js +++ /dev/null @@ -1,73 +0,0 @@ -// For an introduction to the Blank template, see the following documentation: -// https://go.microsoft.com/fwlink/?LinkId=232509 - -(function () { - "use strict"; - - if(typeof Windows !== "undefined") { - initUWP(); - } else { - lime.embed ("::APP_FILE::", "content", ::WIN_WIDTH::, ::WIN_HEIGHT::); - } - - - function initUWP() { - var app = WinJS.Application; - var activation = Windows.ApplicationModel.Activation; - var isFirstActivation = true; - - app.onactivated = function (args) { - if (args.detail.kind === activation.ActivationKind.voiceCommand) { - // TODO: Handle relevant ActivationKinds. For example, if your app can be started by voice commands, - // this is a good place to decide whether to populate an input field or choose a different initial view. - } - else if (args.detail.kind === activation.ActivationKind.launch) { - // A Launch activation happens when the user launches your app via the tile - // or invokes a toast notification by clicking or tapping on the body. - if (args.detail.arguments) { - // TODO: If the app supports toasts, use this value from the toast payload to determine where in the app - // to take the user in response to them invoking a toast notification. - } - else if (args.detail.previousExecutionState === activation.ApplicationExecutionState.terminated) { - // TODO: This application had been suspended and was then terminated to reclaim memory. - // To create a smooth user experience, restore application state here so that it looks like the app never stopped running. - // Note: You may want to record the time when the app was last suspended and only restore state if they've returned after a short period. - } - } - - if (!args.detail.prelaunchActivated) { - // TODO: If prelaunchActivated were true, it would mean the app was prelaunched in the background as an optimization. - // In that case it would be suspended shortly thereafter. - // Any long-running operations (like expensive network or disk I/O) or changes to user state which occur at launch - // should be done here (to avoid doing them in the prelaunch case). - // Alternatively, this work can be done in a resume or visibilitychanged handler. - } - - if (isFirstActivation) { - // TODO: The app was activated and had not been running. Do general startup initialization here. - Debug.writeln("app.onactivated isFirstActivation"); - lime.embed ("::APP_FILE::", "content", ::WIN_WIDTH::, ::WIN_HEIGHT::); - document.addEventListener("visibilitychange", onVisibilityChanged); - args.setPromise(WinJS.UI.processAll()); - } - - isFirstActivation = false; - }; - - function onVisibilityChanged(args) { - if (!document.hidden) { - // TODO: The app just became visible. This may be a good time to refresh the view. - } - } - - app.oncheckpoint = function (args) { - // TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here. - // You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension. - // If you need to complete an asynchronous operation before your application is suspended, call args.setPromise(). - }; - - app.start(); - } - - -})(); diff --git a/templates/winjs/template/source/lib/winjs-4.0.1/css/ui-dark.css b/templates/winjs/template/source/lib/winjs-4.0.1/css/ui-dark.css deleted file mode 100644 index 991c9316d3..0000000000 --- a/templates/winjs/template/source/lib/winjs-4.0.1/css/ui-dark.css +++ /dev/null @@ -1,7304 +0,0 @@ -/* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. */ -@keyframes WinJS-node-inserted { - from { - outline-color: #000; - } - to { - outline-color: #001; - } -} -@keyframes WinJS-opacity-in { - from { - opacity: 0; - } - to { - opacity: 1; - } -} -@keyframes WinJS-opacity-out { - from { - opacity: 1; - } - to { - opacity: 0; - } -} -@keyframes WinJS-scale-up { - from { - transform: scale(0.85); - } - to { - transform: scale(1); - } -} -@keyframes WinJS-scale-down { - from { - transform: scale(1); - } - to { - transform: scale(0.85); - } -} -@keyframes WinJS-default-remove { - from { - transform: translateX(11px); - } - to { - transform: none; - } -} -@keyframes WinJS-default-remove-rtl { - from { - transform: translateX(-11px); - } - to { - transform: none; - } -} -@keyframes WinJS-default-apply { - from { - transform: none; - } - to { - transform: translateX(11px); - } -} -@keyframes WinJS-default-apply-rtl { - from { - transform: none; - } - to { - transform: translateX(-11px); - } -} -@keyframes WinJS-showEdgeUI { - from { - transform: translateY(-70px); - } - to { - transform: none; - } -} -@keyframes WinJS-showPanel { - from { - transform: translateX(364px); - } - to { - transform: none; - } -} -@keyframes WinJS-showPanel-rtl { - from { - transform: translateX(-364px); - } - to { - transform: none; - } -} -@keyframes WinJS-hideEdgeUI { - from { - transform: none; - } - to { - transform: translateY(-70px); - } -} -@keyframes WinJS-hidePanel { - from { - transform: none; - } - to { - transform: translateX(364px); - } -} -@keyframes WinJS-hidePanel-rtl { - from { - transform: none; - } - to { - transform: translateX(-364px); - } -} -@keyframes WinJS-showPopup { - from { - transform: translateY(50px); - } - to { - transform: none; - } -} -@keyframes WinJS-dragSourceEnd { - from { - transform: translateX(11px) scale(1.05); - } - to { - transform: none; - } -} -@keyframes WinJS-dragSourceEnd-rtl { - from { - transform: translateX(-11px) scale(1.05); - } - to { - transform: none; - } -} -@keyframes WinJS-enterContent { - from { - transform: translateY(28px); - } - to { - transform: none; - } -} -@keyframes WinJS-exit { - from { - transform: none; - } - to { - transform: none; - } -} -@keyframes WinJS-enterPage { - from { - transform: translateY(28px); - } - to { - transform: none; - } -} -@keyframes WinJS-updateBadge { - from { - transform: translateY(24px); - } - to { - transform: none; - } -} -@-webkit-keyframes WinJS-node-inserted { - from { - outline-color: #000; - } - to { - outline-color: #001; - } -} -@-webkit-keyframes -webkit-WinJS-opacity-in { - from { - opacity: 0; - } - to { - opacity: 1; - } -} -@-webkit-keyframes -webkit-WinJS-opacity-out { - from { - opacity: 1; - } - to { - opacity: 0; - } -} -@-webkit-keyframes -webkit-WinJS-scale-up { - from { - -webkit-transform: scale(0.85); - } - to { - -webkit-transform: scale(1); - } -} -@-webkit-keyframes -webkit-WinJS-scale-down { - from { - -webkit-transform: scale(1); - } - to { - -webkit-transform: scale(0.85); - } -} -@-webkit-keyframes -webkit-WinJS-default-remove { - from { - -webkit-transform: translateX(11px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-default-remove-rtl { - from { - -webkit-transform: translateX(-11px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-default-apply { - from { - -webkit-transform: none; - } - to { - -webkit-transform: translateX(11px); - } -} -@-webkit-keyframes -webkit-WinJS-default-apply-rtl { - from { - -webkit-transform: none; - } - to { - -webkit-transform: translateX(-11px); - } -} -@-webkit-keyframes -webkit-WinJS-showEdgeUI { - from { - -webkit-transform: translateY(-70px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-showPanel { - from { - -webkit-transform: translateX(364px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-showPanel-rtl { - from { - -webkit-transform: translateX(-364px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-hideEdgeUI { - from { - -webkit-transform: none; - } - to { - -webkit-transform: translateY(-70px); - } -} -@-webkit-keyframes -webkit-WinJS-hidePanel { - from { - -webkit-transform: none; - } - to { - -webkit-transform: translateX(364px); - } -} -@-webkit-keyframes -webkit-WinJS-hidePanel-rtl { - from { - -webkit-transform: none; - } - to { - -webkit-transform: translateX(-364px); - } -} -@-webkit-keyframes -webkit-WinJS-showPopup { - from { - -webkit-transform: translateY(50px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-dragSourceEnd { - from { - -webkit-transform: translateX(11px) scale(1.05); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-dragSourceEnd-rtl { - from { - -webkit-transform: translateX(-11px) scale(1.05); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-enterContent { - from { - -webkit-transform: translateY(28px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-exit { - from { - -webkit-transform: none; - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-enterPage { - from { - -webkit-transform: translateY(28px); - } - to { - -webkit-transform: none; - } -} -@-webkit-keyframes -webkit-WinJS-updateBadge { - from { - -webkit-transform: translateY(24px); - } - to { - -webkit-transform: none; - } -} -@font-face { - font-family: "Segoe UI Command"; - src: local("Segoe MDL2 Assets"); - font-weight: normal; - font-style: normal; -} -@font-face { - font-family: "Symbols"; - src: url(../fonts/Symbols.ttf); -} -.win-type-header, -.win-h1 { - font-size: 46px; - font-weight: 200; - line-height: 1.216; - letter-spacing: 0px; -} -.win-type-subheader, -.win-h2 { - font-size: 34px; - font-weight: 200; - line-height: 1.176; -} -.win-type-title, -.win-h3 { - font-size: 24px; - font-weight: 300; - line-height: 1.167; -} -.win-type-subtitle, -.win-h4 { - font-size: 20px; - font-weight: 400; - line-height: 1.2; -} -.win-type-body, -.win-h6 { - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-type-base, -.win-h5 { - font-size: 15px; - font-weight: 500; - line-height: 1.333; -} -.win-type-caption { - font-size: 12px; - font-weight: 400; - line-height: 1.167; -} -@font-face { - font-family: "Segoe UI"; - font-weight: 200; - src: local("Segoe UI Light"); -} -@font-face { - font-family: "Segoe UI"; - font-weight: 300; - src: local("Segoe UI Semilight"); -} -@font-face { - font-family: "Segoe UI"; - font-weight: 400; - src: local("Segoe UI"); -} -@font-face { - font-family: "Segoe UI"; - font-weight: 500; - src: local("Segoe UI Semibold"); -} -@font-face { - font-family: "Segoe UI"; - font-weight: 600; - src: local("Segoe UI Bold"); -} -@font-face { - font-family: "Segoe UI"; - font-style: italic; - font-weight: 400; - src: local("Segoe UI Italic"); -} -@font-face { - font-family: "Segoe UI"; - font-style: italic; - font-weight: 700; - src: local("Segoe UI Bold Italic"); -} -@font-face { - font-family: "Microsoft Yahei UI"; - font-weight: 200; - src: local("Microsoft Yahei UI Light"); -} -@font-face { - font-family: "Microsoft Yahei UI"; - font-weight: 300; - src: local("Microsoft Yahei UI"); -} -@font-face { - font-family: "Microsoft Yahei UI"; - font-weight: 500; - src: local("Microsoft Yahei UI"); -} -@font-face { - font-family: "Microsoft Yahei UI"; - font-weight: 600; - src: local("Microsoft Yahei UI Bold"); -} -@font-face { - font-family: "Microsoft JhengHei UI"; - font-weight: 200; - src: local("Microsoft JhengHei UI Light"); -} -@font-face { - font-family: "Microsoft JhengHei UI"; - font-weight: 300; - src: local("Microsoft JhengHei UI"); -} -@font-face { - font-family: "Microsoft JhengHei UI"; - font-weight: 500; - src: local("Microsoft JhengHei UI"); -} -@font-face { - font-family: "Microsoft JhengHei UI"; - font-weight: 600; - src: local("Microsoft JhengHei UI Bold"); -} -.win-type-header:-ms-lang(am, ti), -.win-type-subheader:-ms-lang(am, ti), -.win-type-title:-ms-lang(am, ti), -.win-type-subtitle:-ms-lang(am, ti), -.win-type-base:-ms-lang(am, ti), -.win-type-body:-ms-lang(am, ti), -.win-type-caption:-ms-lang(am, ti), -.win-h1:-ms-lang(am, ti), -.win-h2:-ms-lang(am, ti), -.win-h3:-ms-lang(am, ti), -.win-h4:-ms-lang(am, ti), -.win-h5:-ms-lang(am, ti), -.win-h6:-ms-lang(am, ti), -.win-button:-ms-lang(am, ti), -.win-dropdown:-ms-lang(am, ti), -.win-textbox:-ms-lang(am, ti), -.win-link:-ms-lang(am, ti), -.win-textarea:-ms-lang(am, ti) { - font-family: "Ebrima", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-subheader:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-title:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-subtitle:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-base:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-body:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-type-caption:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h1:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h2:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h3:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h4:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h5:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-h6:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-button:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-dropdown:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-textbox:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-link:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te), -.win-textarea:-ms-lang(as, bn, gu, hi, kn, kok, ml, mr, ne, or, pa, sat-Olck, si, srb-Sora, ta, te) { - font-family: "Nirmala UI", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(chr-CHER-US), -.win-type-subheader:-ms-lang(chr-CHER-US), -.win-type-title:-ms-lang(chr-CHER-US), -.win-type-subtitle:-ms-lang(chr-CHER-US), -.win-type-base:-ms-lang(chr-CHER-US), -.win-type-body:-ms-lang(chr-CHER-US), -.win-type-caption:-ms-lang(chr-CHER-US), -.win-h1:-ms-lang(chr-CHER-US), -.win-h2:-ms-lang(chr-CHER-US), -.win-h3:-ms-lang(chr-CHER-US), -.win-h4:-ms-lang(chr-CHER-US), -.win-h5:-ms-lang(chr-CHER-US), -.win-h6:-ms-lang(chr-CHER-US), -.win-button:-ms-lang(chr-CHER-US), -.win-dropdown:-ms-lang(chr-CHER-US), -.win-textbox:-ms-lang(chr-CHER-US), -.win-link:-ms-lang(chr-CHER-US), -.win-textarea:-ms-lang(chr-CHER-US) { - font-family: "Gadugi", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(ja), -.win-type-subheader:-ms-lang(ja), -.win-type-title:-ms-lang(ja), -.win-type-subtitle:-ms-lang(ja), -.win-type-base:-ms-lang(ja), -.win-type-body:-ms-lang(ja), -.win-type-caption:-ms-lang(ja), -.win-h1:-ms-lang(ja), -.win-h2:-ms-lang(ja), -.win-h3:-ms-lang(ja), -.win-h4:-ms-lang(ja), -.win-h5:-ms-lang(ja), -.win-h6:-ms-lang(ja), -.win-button:-ms-lang(ja), -.win-dropdown:-ms-lang(ja), -.win-textbox:-ms-lang(ja), -.win-link:-ms-lang(ja), -.win-textarea:-ms-lang(ja) { - font-family: "Yu Gothic UI", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(km, lo, th, bug-Bugi), -.win-type-subheader:-ms-lang(km, lo, th, bug-Bugi), -.win-type-title:-ms-lang(km, lo, th, bug-Bugi), -.win-type-subtitle:-ms-lang(km, lo, th, bug-Bugi), -.win-type-base:-ms-lang(km, lo, th, bug-Bugi), -.win-type-body:-ms-lang(km, lo, th, bug-Bugi), -.win-type-caption:-ms-lang(km, lo, th, bug-Bugi), -.win-h1:-ms-lang(km, lo, th, bug-Bugi), -.win-h2:-ms-lang(km, lo, th, bug-Bugi), -.win-h3:-ms-lang(km, lo, th, bug-Bugi), -.win-h4:-ms-lang(km, lo, th, bug-Bugi), -.win-h5:-ms-lang(km, lo, th, bug-Bugi), -.win-h6:-ms-lang(km, lo, th, bug-Bugi), -.win-button:-ms-lang(km, lo, th, bug-Bugi), -.win-dropdown:-ms-lang(km, lo, th, bug-Bugi), -.win-textbox:-ms-lang(km, lo, th, bug-Bugi), -.win-link:-ms-lang(km, lo, th, bug-Bugi), -.win-textarea:-ms-lang(km, lo, th, bug-Bugi) { - font-family: "Leelawadee UI", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(ko), -.win-type-subheader:-ms-lang(ko), -.win-type-title:-ms-lang(ko), -.win-type-subtitle:-ms-lang(ko), -.win-type-base:-ms-lang(ko), -.win-type-body:-ms-lang(ko), -.win-type-caption:-ms-lang(ko), -.win-h1:-ms-lang(ko), -.win-h2:-ms-lang(ko), -.win-h3:-ms-lang(ko), -.win-h4:-ms-lang(ko), -.win-h5:-ms-lang(ko), -.win-h6:-ms-lang(ko), -.win-button:-ms-lang(ko), -.win-dropdown:-ms-lang(ko), -.win-textbox:-ms-lang(ko), -.win-link:-ms-lang(ko), -.win-textarea:-ms-lang(ko) { - font-family: "Malgun Gothic", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(jv-Java), -.win-type-subheader:-ms-lang(jv-Java), -.win-type-title:-ms-lang(jv-Java), -.win-type-subtitle:-ms-lang(jv-Java), -.win-type-base:-ms-lang(jv-Java), -.win-type-body:-ms-lang(jv-Java), -.win-type-caption:-ms-lang(jv-Java), -.win-h1:-ms-lang(jv-Java), -.win-h2:-ms-lang(jv-Java), -.win-h3:-ms-lang(jv-Java), -.win-h4:-ms-lang(jv-Java), -.win-h5:-ms-lang(jv-Java), -.win-h6:-ms-lang(jv-Java), -.win-button:-ms-lang(jv-Java), -.win-dropdown:-ms-lang(jv-Java), -.win-textbox:-ms-lang(jv-Java), -.win-link:-ms-lang(jv-Java), -.win-textarea:-ms-lang(jv-Java) { - font-family: "Javanese Text", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(cop-Copt), -.win-type-subheader:-ms-lang(cop-Copt), -.win-type-title:-ms-lang(cop-Copt), -.win-type-subtitle:-ms-lang(cop-Copt), -.win-type-base:-ms-lang(cop-Copt), -.win-type-body:-ms-lang(cop-Copt), -.win-type-caption:-ms-lang(cop-Copt), -.win-h1:-ms-lang(cop-Copt), -.win-h2:-ms-lang(cop-Copt), -.win-h3:-ms-lang(cop-Copt), -.win-h4:-ms-lang(cop-Copt), -.win-h5:-ms-lang(cop-Copt), -.win-h6:-ms-lang(cop-Copt), -.win-button:-ms-lang(cop-Copt), -.win-dropdown:-ms-lang(cop-Copt), -.win-textbox:-ms-lang(cop-Copt), -.win-link:-ms-lang(cop-Copt), -.win-textarea:-ms-lang(cop-Copt) { - font-family: "Segoe MDL2 Assets", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-subheader:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-title:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-subtitle:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-base:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-body:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-type-caption:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h1:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h2:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h3:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h4:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h5:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-h6:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-button:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-dropdown:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-textbox:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-link:-ms-lang(zh-CN, zh-Hans, zh-SG), -.win-textarea:-ms-lang(zh-CN, zh-Hans, zh-SG) { - font-family: "Microsoft YaHei UI", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -.win-type-header:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-subheader:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-title:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-subtitle:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-base:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-body:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-type-caption:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h1:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h2:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h3:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h4:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h5:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-h6:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-button:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-dropdown:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-textbox:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-link:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO), -.win-textarea:-ms-lang(zh-HK, zh-TW, zh-Hant, zh-MO) { - font-family: "Microsoft JhengHei UI", "Ebrima", "Nirmala UI", "Gadugi", "Segoe UI Emoji", "Segoe MDL2 Assets", "Symbols", "Yu Gothic UI", "Yu Gothic", "Meiryo UI", "Leelawadee UI", "Microsoft YaHei UI", "Microsoft JhengHei UI", "Malgun Gothic", "Segoe UI Historic", "Estrangelo Edessa", "Microsoft Himalaya", "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text", "Javanese Text", "Cambria Math"; -} -html, -body { - width: 100%; - height: 100%; - margin: 0px; - cursor: default; - -webkit-touch-callout: none; - -ms-scroll-translation: vertical-to-horizontal; - -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -} -html { - overflow: hidden; - direction: ltr; -} -html:lang(ar), -html:lang(dv), -html:lang(fa), -html:lang(he), -html:lang(ku-Arab), -html:lang(pa-Arab), -html:lang(prs), -html:lang(ps), -html:lang(sd-Arab), -html:lang(syr), -html:lang(ug), -html:lang(ur), -html:lang(qps-plocm) { - direction: rtl; -} -body { - -ms-content-zooming: none; -} -iframe { - border: 0; -} -.win-type-header, -.win-type-subheader, -.win-type-title, -.win-type-subtitle, -.win-type-base, -.win-type-body, -.win-type-caption, -.win-h1, -.win-h2, -.win-h3, -.win-h4, -.win-h5, -.win-h6, -.win-button, -.win-dropdown, -.win-textbox, -.win-link, -.win-textarea { - font-family: "Segoe UI", sans-serif, "Segoe MDL2 Assets", "Symbols"; -} -.win-textbox, -.win-textarea { - -ms-user-select: element; - border-style: solid; - border-width: 2px; - border-radius: 0; - margin: 8px 0px; - width: 296px; - min-width: 64px; - min-height: 28px; - background-clip: border-box; - box-sizing: border-box; - padding: 3px 6px 5px 10px; - outline: 0; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-textbox::-ms-value { - margin: 0; - padding: 0; -} -.win-textbox::-ms-clear, -.win-textbox::-ms-reveal { - padding-right: 2px; - margin-right: -8px; - margin-left: 2px; - margin-top: -8px; - margin-bottom: -8px; - width: 30px; - height: 32px; -} -.win-textbox:lang(ar)::-ms-clear, -.win-textbox:lang(dv)::-ms-clear, -.win-textbox:lang(fa)::-ms-clear, -.win-textbox:lang(he)::-ms-clear, -.win-textbox:lang(ku-Arab)::-ms-clear, -.win-textbox:lang(pa-Arab)::-ms-clear, -.win-textbox:lang(prs)::-ms-clear, -.win-textbox:lang(ps)::-ms-clear, -.win-textbox:lang(sd-Arab)::-ms-clear, -.win-textbox:lang(syr)::-ms-clear, -.win-textbox:lang(ug)::-ms-clear, -.win-textbox:lang(ur)::-ms-clear, -.win-textbox:lang(qps-plocm)::-ms-clear, -.win-textbox:lang(ar)::-ms-reveal, -.win-textbox:lang(dv)::-ms-reveal, -.win-textbox:lang(fa)::-ms-reveal, -.win-textbox:lang(he)::-ms-reveal, -.win-textbox:lang(ku-Arab)::-ms-reveal, -.win-textbox:lang(pa-Arab)::-ms-reveal, -.win-textbox:lang(prs)::-ms-reveal, -.win-textbox:lang(ps)::-ms-reveal, -.win-textbox:lang(sd-Arab)::-ms-reveal, -.win-textbox:lang(syr)::-ms-reveal, -.win-textbox:lang(ug)::-ms-reveal, -.win-textbox:lang(ur)::-ms-reveal, -.win-textbox:lang(qps-plocm)::-ms-reveal { - margin-left: -8px; - margin-right: 2px; -} -.win-textarea { - resize: none; - overflow-y: auto; -} -.win-radio, -.win-checkbox { - width: 20px; - height: 20px; - margin-right: 8px; - margin-top: 12px; - margin-bottom: 12px; -} -.win-radio:lang(ar), -.win-checkbox:lang(ar), -.win-radio:lang(dv), -.win-checkbox:lang(dv), -.win-radio:lang(fa), -.win-checkbox:lang(fa), -.win-radio:lang(he), -.win-checkbox:lang(he), -.win-radio:lang(ku-Arab), -.win-checkbox:lang(ku-Arab), -.win-radio:lang(pa-Arab), -.win-checkbox:lang(pa-Arab), -.win-radio:lang(prs), -.win-checkbox:lang(prs), -.win-radio:lang(ps), -.win-checkbox:lang(ps), -.win-radio:lang(sd-Arab), -.win-checkbox:lang(sd-Arab), -.win-radio:lang(syr), -.win-checkbox:lang(syr), -.win-radio:lang(ug), -.win-checkbox:lang(ug), -.win-radio:lang(ur), -.win-checkbox:lang(ur), -.win-radio:lang(qps-plocm), -.win-checkbox:lang(qps-plocm) { - margin-left: 8px; - margin-right: 0px; -} -.win-radio::-ms-check, -.win-checkbox::-ms-check { - border-style: solid; - display: inline-block; - border-width: 2px; - background-clip: border-box; -} -.win-button { - border-style: solid; - margin: 0px; - min-height: 32px; - min-width: 120px; - padding: 4px 8px; - border-width: 2px; - background-clip: border-box; - border-radius: 0; - touch-action: manipulation; - -webkit-appearance: none; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-button.win-button-file { - border: none; - min-width: 100px; - min-height: 20px; - width: 340px; - height: 32px; - padding: 0px; - margin: 7px 8px 21px 8px; - background-clip: padding-box; -} -.win-button.win-button-file::-ms-value { - margin: 0; - border-width: 2px; - border-style: solid; - border-right-style: none; - border-radius: 0; - background-clip: border-box; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-button.win-button-file:lang(ar)::-ms-value, -.win-button.win-button-file:lang(dv)::-ms-value, -.win-button.win-button-file:lang(fa)::-ms-value, -.win-button.win-button-file:lang(he)::-ms-value, -.win-button.win-button-file:lang(ku-Arab)::-ms-value, -.win-button.win-button-file:lang(pa-Arab)::-ms-value, -.win-button.win-button-file:lang(prs)::-ms-value, -.win-button.win-button-file:lang(ps)::-ms-value, -.win-button.win-button-file:lang(sd-Arab)::-ms-value, -.win-button.win-button-file:lang(syr)::-ms-value, -.win-button.win-button-file:lang(ug)::-ms-value, -.win-button.win-button-file:lang(ur)::-ms-value, -.win-button.win-button-file:lang(qps-plocm)::-ms-value { - border-left-style: none; - border-right-style: solid; -} -.win-button.win-button-file::-ms-browse { - margin: 0; - padding: 0 18px; - border-width: 2px; - border-style: solid; - background-clip: padding-box; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-dropdown { - min-width: 56px; - max-width: 368px; - min-height: 32px; - margin: 8px 0; - border-style: solid; - border-width: 2px; - background-clip: border-box; - background-image: none; - box-sizing: border-box; - border-radius: 0; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-dropdown::-ms-value { - padding: 5px 12px 7px 12px; - margin: 0; -} -.win-dropdown::-ms-expand { - border: none; - margin-right: 5px; - margin-left: 3px; - margin-bottom: -2px; - font-size: 20px; -} -select[multiple].win-dropdown { - padding: 0 0 0 12px; - vertical-align: bottom; -} -.win-dropdown option { - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-progress-bar, -.win-progress-ring, -.win-ring { - width: 180px; - height: 4px; - -webkit-appearance: none; -} -.win-progress-bar:not(:indeterminate), -.win-progress-ring:not(:indeterminate), -.win-ring:not(:indeterminate) { - border-style: none; -} -.win-progress-bar::-ms-fill, -.win-progress-ring::-ms-fill, -.win-ring::-ms-fill { - border-style: none; -} -.win-progress-bar.win-medium, -.win-progress-ring.win-medium, -.win-ring.win-medium { - width: 296px; -} -.win-progress-bar.win-large, -.win-progress-ring.win-large, -.win-ring.win-large { - width: 100%; -} -.win-progress-bar:indeterminate::-webkit-progress-value, -.win-progress-ring:indeterminate::-webkit-progress-value, -.win-ring:indeterminate::-webkit-progress-value { - position: relative; - -webkit-animation: win-progress-indeterminate 3s linear infinite; -} -.win-progress-bar.win-paused:not(:indeterminate), -.win-progress-ring.win-paused:not(:indeterminate), -.win-ring.win-paused:not(:indeterminate) { - animation-name: win-progress-fade-out; - animation-duration: 3s; - animation-timing-function: cubic-bezier(0.03, 0.76, 0.31, 1); - opacity: 0.5; -} -.win-progress-bar.win-error::-ms-fill, -.win-progress-ring.win-error::-ms-fill, -.win-ring.win-error::-ms-fill { - opacity: 0; -} -.win-progress-ring, -.win-ring { - width: 20px; - height: 20px; -} -.win-progress-ring:indeterminate::-ms-fill, -.win-ring:indeterminate::-ms-fill { - animation-name: -ms-ring; -} -.win-progress-ring.win-medium, -.win-ring.win-medium { - width: 40px; - height: 40px; -} -.win-progress-ring.win-large, -.win-ring.win-large { - width: 60px; - height: 60px; -} -@-webkit-keyframes win-progress-indeterminate { - 0% { - left: 0; - width: 25%; - } - 50% { - left: calc(75%); - width: 25%; - } - 75% { - left: calc(100%); - width: 0%; - } - 75.1% { - left: 0; - width: 0%; - } - 100% { - left: 0; - width: 25%; - } -} -@keyframes win-progress-fade-out { - from { - opacity: 1.0; - } - to { - opacity: 0.5; - } -} -.win-slider { - -webkit-appearance: none; - width: 280px; - height: 22px; - padding-top: 17px; - padding-bottom: 32px; -} -.win-slider::-ms-track { - height: 2px; - border-style: none; -} -.win-slider::-webkit-slider-runnable-track { - height: 2px; - border-style: none; -} -.win-slider::-moz-range-track { - height: 2px; - border-style: none; -} -.win-slider::-ms-thumb { - width: 24px; - height: 8px; - border-radius: 4px; - border-style: none; -} -.win-slider::-webkit-slider-thumb { - -webkit-appearance: none; - margin-top: -4px; - width: 24px; - height: 8px; - border-radius: 4px; - border-style: none; -} -.win-slider::-moz-range-thumb { - width: 24px; - height: 8px; - border-radius: 4px; - border-style: none; -} -.win-slider.win-vertical { - writing-mode: bt-lr; - width: 22px; - height: 280px; -} -.win-slider.win-vertical::-ms-track { - width: 2px; - height: auto; -} -.win-slider.win-vertical::-ms-thumb { - width: 8px; - height: 24px; -} -.win-slider.win-vertical:lang(ar), -.win-slider.win-vertical:lang(dv), -.win-slider.win-vertical:lang(fa), -.win-slider.win-vertical:lang(he), -.win-slider.win-vertical:lang(ku-Arab), -.win-slider.win-vertical:lang(pa-Arab), -.win-slider.win-vertical:lang(prs), -.win-slider.win-vertical:lang(ps), -.win-slider.win-vertical:lang(sd-Arab), -.win-slider.win-vertical:lang(syr), -.win-slider.win-vertical:lang(ug), -.win-slider.win-vertical:lang(ur), -.win-slider.win-vertical:lang(qps-plocm) { - writing-mode: bt-rl; -} -.win-link { - text-decoration: underline; - cursor: pointer; - touch-action: manipulation; -} -.win-code { - font-family: "Consolas", "Menlo", "Monaco", "Courier New", monospace; - font-size: 15px; - font-weight: 400; - line-height: 1.333; -} -.win-type-ellipsis { - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} -h1.win-type-ellipsis, -.win-type-header.win-type-ellipsis, -.win-h1.win-type-ellipsis { - line-height: 1.4286; -} -h2.win-type-ellipsis, -.win-type-subheader.win-type-ellipsis, -.win-h2.win-type-ellipsis { - line-height: 1.5; -} -.win-scrollview { - overflow-x: auto; - overflow-y: hidden; - height: 400px; - width: 100%; -} -h1.win-type-header, -h2.win-type-subheader, -h3.win-type-title, -h4.win-type-subtitle, -h5.win-type-base, -h6.win-type-body, -h1.win-h1, -h2.win-h2, -h3.win-h3, -h4.win-h4, -h5.win-h5, -h6.win-h6 { - margin-top: 0px; - margin-bottom: 0px; -} -.win-type-body p, -p.win-type-body { - font-weight: 300; -} -.win-listview { - overflow: hidden; - height: 400px; -} -.win-listview .win-surface { - overflow: visible; -} -.win-listview > .win-viewport.win-horizontal .win-surface { - height: 100%; -} -.win-listview > .win-viewport.win-vertical .win-surface { - width: 100%; -} -.win-listview > .win-viewport { - position: relative; - width: 100%; - height: 100%; - z-index: 0; - -ms-overflow-style: -ms-autohiding-scrollbar; - -webkit-overflow-scrolling: touch; - white-space: nowrap; -} -.win-listview > .win-viewport.win-horizontal { - overflow-x: auto; - overflow-y: hidden; -} -.win-listview > .win-viewport.win-vertical { - overflow-x: hidden; - overflow-y: auto; -} -.win-listview .win-itemscontainer { - overflow: hidden; -} -.win-listview .win-itemscontainer-padder { - width: 0; - height: 0; - margin: 0; - padding: 0; - border: 0; - overflow: hidden; -} -.win-listview > .win-horizontal .win-container { - margin: 10px 5px 0px 5px; -} -.win-listview > .win-vertical .win-container { - margin: 10px 24px 0px 7px; -} -.win-listview.win-rtl > .win-vertical .win-container { - margin: 10px 7px 0px 24px; -} -.win-listview .win-container, -.win-listview .win-itembox, -.win-itemcontainer.win-container, -.win-itemcontainer .win-itembox { - cursor: default; - z-index: 0; -} -.win-listview .win-container { - touch-action: pan-x pan-y pinch-zoom; -} -.win-semanticzoom .win-listview > .win-viewport * { - touch-action: auto; -} -.win-semanticzoom .win-listview > .win-viewport.win-zooming-x { - overflow-x: visible; -} -.win-semanticzoom .win-listview > .win-viewport.win-zooming-y { - overflow-y: visible; -} -.win-listview .win-itembox, -.win-itemcontainer .win-itembox { - width: 100%; - height: 100%; -} -.win-listview .win-item, -.win-itemcontainer .win-item { - z-index: 1; -} -.win-listview .win-item, -.win-itemcontainer .win-item { - overflow: hidden; - position: relative; -} -.win-listview > .win-vertical .win-item { - width: 100%; -} -.win-listview .win-item:focus, -.win-itemcontainer .win-item:focus { - outline-style: none; -} -.win-listview .win-focusedoutline, -.win-itemcontainer .win-focusedoutline { - width: calc(100% - 4px); - height: calc(100% - 4px); - left: 2px; - top: 2px; - position: absolute; - z-index: 5; - pointer-events: none; -} -.win-container.win-selected .win-selectionborder { - border-width: 2px; - border-style: solid; -} -html.win-hoverable .win-container.win-selected:hover .win-selectionborder { - border-width: 2px; - border-style: solid; -} -html.win-hoverable .win-listview .win-itembox:hover::before, -html.win-hoverable .win-itemcontainer .win-itembox:hover::before { - position: absolute; - left: 0px; - top: 0px; - content: ""; - width: calc(100% - 4px); - height: calc(100% - 4px); - pointer-events: none; - border-style: solid; - border-width: 2px; - z-index: 3; -} -html.win-hoverable .win-listview.win-selectionstylefilled .win-itembox:hover::before, -html.win-hoverable .win-itemcontainer.win-selectionstylefilled .win-itembox:hover::before, -html.win-hoverable .win-listview .win-itembox.win-selected:hover::before, -html.win-hoverable .win-itemcontainer.win-itembox.win-selected:hover::before, -html.win-hoverable .win-itemcontainer.win-itembox.win-selected:hover::before { - display: none; -} -.win-listview .win-groupheader { - padding: 10px 10px 10px 2px; - overflow: hidden; - outline-width: 0.01px; - outline-style: none; - float: left; - font-size: 34px; - font-weight: 200; - line-height: 1.176; -} -.win-listview .win-groupheadercontainer { - z-index: 1; - touch-action: pan-x pan-y pinch-zoom; - overflow: hidden; -} -.win-listview .win-horizontal .win-headercontainer, -.win-listview .win-horizontal .win-footercontainer { - height: 100%; - display: inline-block; - overflow: hidden; - white-space: normal; -} -.win-listview .win-vertical .win-headercontainer, -.win-listview .win-vertical .win-footercontainer { - width: 100%; - display: block; - overflow: hidden; - white-space: normal; -} -.win-listview .win-groupheader.win-focused { - outline-style: dotted; -} -.win-listview.win-rtl .win-groupheader { - padding-left: 10px; - padding-right: 2px; - float: right; -} -.win-listview.win-groups .win-horizontal .win-groupleader { - margin-left: 70px; -} -.win-listview.win-groups.win-rtl .win-horizontal .win-groupleader { - margin-left: 0; - margin-right: 70px; -} -.win-listview.win-groups .win-vertical .win-listlayout .win-groupleader, -.win-listview.win-groups .win-vertical .win-gridlayout .win-groupleader { - margin-top: 70px; -} -.win-listview.win-groups > .win-vertical .win-surface.win-listlayout, -.win-listview.win-groups > .win-vertical .win-surface.win-gridlayout { - margin-top: -65px; -} -.win-listview.win-groups > .win-horizontal .win-surface { - margin-left: -70px; -} -.win-listview.win-groups.win-rtl > .win-horizontal .win-surface { - margin-left: 0; - margin-right: -70px; -} -.win-listview .win-surface { - -webkit-margin-collapse: separate; - white-space: normal; -} -.win-surface ._win-proxy { - position: relative; - overflow: hidden; - width: 0; - height: 0; - touch-action: none; -} -.win-selectionborder { - position: absolute; - opacity: inherit; - z-index: 2; - pointer-events: none; -} -.win-container.win-selected .win-selectionborder { - top: 0; - left: 0; - right: 0; - bottom: 0; -} -.win-selectionbackground { - position: absolute; - top: 0; - left: 0; - right: 0; - bottom: 0; - z-index: 0; -} -.win-selectioncheckmarkbackground { - position: absolute; - top: 2px; - right: 2px; - width: 14px; - height: 11px; - margin: 0; - padding: 0; - border-left-width: 2px; - border-right-width: 2px; - border-top-width: 4px; - border-bottom-width: 3px; - border-style: solid; - z-index: 3; - display: none; -} -.win-listview.win-rtl .win-selectioncheckmarkbackground, -.win-itemcontainer.win-rtl .win-selectioncheckmarkbackground { - left: 2px; - right: auto; -} -.win-selectionmode.win-itemcontainer .win-selectioncheckmarkbackground, -.win-selectionmode.win-itemcontainer.win-selectionmode .win-selectioncheckmark, -.win-selectionmode .win-itemcontainer .win-selectioncheckmarkbackground, -.win-selectionmode .win-itemcontainer.win-selectionmode .win-selectioncheckmark, -.win-listview .win-selectionmode .win-selectioncheckmarkbackground, -.win-listview .win-selectionmode .win-selectioncheckmark { - display: block; -} -.win-selectioncheckmark { - position: absolute; - margin: 0; - padding: 2px; - right: 1px; - top: 1px; - font-family: "Segoe MDL2 Assets", "Symbols"; - font-size: 14px; - z-index: 4; - line-height: 1; - display: none; -} -.win-rtl .win-selectioncheckmark { - right: auto; - left: 0px; -} -.win-selectionstylefilled.win-container, -.win-selectionstylefilled .win-container { - overflow: hidden; -} -.win-selectionmode .win-itemcontainer.win-container .win-itembox::after, -.win-selectionmode.win-itemcontainer.win-container .win-itembox::after, -.win-listview .win-surface.win-selectionmode .win-itembox::after { - content: ""; - position: absolute; - width: 18px; - height: 18px; - pointer-events: none; - right: 2px; - top: 2px; - z-index: 3; -} -.win-rtl .win-selectionmode .win-itemcontainer.win-container .win-itembox::after, -.win-itemcontainer.win-rtl.win-selectionmode.win-container .win-itembox::after, -.win-listview.win-rtl .win-surface.win-selectionmode .win-itembox::after { - right: auto; - left: 2px; -} -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-item { - transition: transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - -webkit-transition: -webkit-transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - transform: translate(40px, 0px); - -webkit-transform: translate(40px, 0px); -} -.win-listview.win-rtl.win-selectionstylefilled .win-surface.win-selectionmode .win-item { - transition: transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - -webkit-transition: -webkit-transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - transform: translate(-40px, 0px); - -webkit-transform: translate(-40px, 0px); -} -.win-listview.win-selectionstylefilled .win-surface.win-hidingselectionmode .win-item { - transition: transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - -webkit-transition: -webkit-transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - transform: none; - -webkit-transform: none; -} -.win-listview.win-rtl.win-selectionstylefilled .win-surface.win-hideselectionmode .win-item { - transition: transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - -webkit-transition: -webkit-transform 250ms cubic-bezier(0.17, 0.79, 0.215, 1.0025); - transform: none; - -webkit-transform: none; -} -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-itembox::after { - left: 12px; - right: auto; - top: 50%; - margin-top: -9px; - display: block; - border: 2px solid; - width: 16px; - height: 16px; -} -.win-listview.win-selectionstylefilled.win-rtl .win-surface.win-selectionmode .win-itembox::after { - left: auto; - right: 12px; -} -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-selectioncheckmarkbackground { - left: 12px; - top: 50%; - margin-top: -9px; - display: block; - border: 2px solid; - width: 16px; - height: 16px; -} -.win-listview.win-selectionstylefilled.win-rtl .win-surface.win-selectionmode .win-selectioncheckmarkbackground { - left: auto; - right: 12px; -} -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-selectioncheckmark { - left: 13px; - top: 50%; - margin-top: -8px; - display: block; - width: 14px; - height: 14px; -} -.win-listview.win-selectionstylefilled.win-rtl .win-surface.win-selectionmode .win-selectioncheckmark { - left: 0; - right: 10px; -} -.win-selectionmode .win-itemcontainer.win-selectionstylefilled.win-container .win-itembox.win-selected::after, -.win-itemcontainer.win-selectionmode.win-selectionstylefilled.win-container .win-itembox.win-selected::after, -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-itembox.win-nonselectable::after, -.win-listview .win-surface.win-selectionmode .win-itembox.win-selected::after { - display: none; -} -.win-listview .win-progress { - left: 50%; - top: 50%; - width: 60px; - height: 60px; - margin-left: -30px; - margin-top: -30px; - z-index: 1; - position: absolute; -} -.win-listview .win-progress::-ms-fill { - animation-name: -ms-ring; -} -.win-listview .win-itemsblock { - overflow: hidden; -} -.win-listview .win-surface.win-nocssgrid.win-gridlayout, -.win-listview .win-horizontal .win-nocssgrid.win-listlayout, -.win-listview .win-vertical .win-nocssgrid.win-listlayout.win-headerpositionleft { - display: -ms-inline-flexbox; - display: -webkit-inline-flex; - display: inline-flex; - vertical-align: top; -} -.win-listview .win-horizontal .win-surface.win-nocssgrid { - -ms-flex-direction: column; - -webkit-flex-direction: column; - flex-direction: column; - -ms-flex-wrap: wrap; - -webkit-flex-wrap: wrap; - flex-wrap: wrap; - -ms-flex-line-pack: start; - -webkit-align-content: flex-start; - align-content: flex-start; -} -.win-listview .win-vertical .win-surface.win-nocssgrid { - -ms-flex-direction: row; - -webkit-flex-direction: row; - flex-direction: row; - -ms-flex-wrap: wrap; - -webkit-flex-wrap: wrap; - flex-wrap: wrap; - -ms-flex-line-pack: start; - -webkit-align-content: flex-start; - align-content: flex-start; -} -.win-listview .win-vertical .win-structuralnodes.win-single-itemsblock.win-listlayout .win-itemscontainer.win-laidout, -.win-listview .win-horizontal .win-structuralnodes.win-single-itemsblock.win-listlayout .win-itemscontainer.win-laidout, -.win-listview .win-vertical .win-structuralnodes.win-single-itemsblock.win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout, -.win-listview .win-horizontal .win-structuralnodes.win-single-itemsblock.win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout { - display: block; -} -.win-listview .win-vertical .win-structuralnodes.win-single-itemsblock.win-listlayout .win-itemscontainer.win-laidout .win-itemscontainer-padder, -.win-listview .win-horizontal .win-structuralnodes.win-single-itemsblock.win-listlayout .win-itemscontainer.win-laidout .win-itemscontainer-padder, -.win-listview .win-vertical .win-structuralnodes.win-single-itemsblock.win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout .win-itemscontainer-padder, -.win-listview .win-horizontal .win-structuralnodes.win-single-itemsblock.win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout .win-itemscontainer-padder { - height: 0; - width: 0; -} -.win-listview.win-groups .win-vertical .win-listlayout.win-headerpositionleft .win-itemscontainer, -.win-listview.win-groups .win-vertical .win-listlayout.win-headerpositionleft .win-groupheadercontainer, -.win-listview.win-groups .win-horizontal .win-listlayout .win-itemscontainer, -.win-listview.win-groups .win-horizontal .win-listlayout .win-groupheadercontainer { - display: none; -} -.win-listview.win-groups .win-vertical .win-listlayout.win-headerpositionleft .win-itemscontainer.win-laidout, -.win-listview.win-groups .win-vertical .win-listlayout.win-headerpositionleft .win-groupheadercontainer.win-laidout, -.win-listview.win-groups .win-horizontal .win-listlayout .win-groupheadercontainer.win-laidout { - display: block; -} -.win-listview .win-listlayout .win-itemscontainer { - overflow: visible; -} -.win-listview .win-listlayout .win-itemsblock { - padding-bottom: 4px; - margin-bottom: -4px; -} -.win-listview > .win-vertical .win-listlayout.win-headerpositiontop .win-groupheader { - float: none; -} -.win-listview > .win-vertical .win-surface.win-listlayout { - margin-bottom: 5px; -} -.win-listview .win-vertical .win-listlayout.win-headerpositionleft.win-surface { - display: -ms-inline-grid; - -ms-grid-columns: auto 1fr; - -ms-grid-rows: auto; -} -.win-listview .win-vertical .win-listlayout.win-headerpositionleft .win-groupheadercontainer { - -ms-grid-column: 1; -} -.win-listview .win-vertical .win-listlayout.win-headerpositionleft .win-itemscontainer { - -ms-grid-column: 2; -} -.win-listview > .win-horizontal .win-surface.win-listlayout { - display: -ms-inline-grid; - -ms-grid-columns: auto; - -ms-grid-rows: auto; - vertical-align: top; -} -.win-listview .win-horizontal .win-listlayout .win-itemsblock { - height: 100%; -} -.win-listview .win-horizontal .win-listlayout .win-itemscontainer { - margin-bottom: 24px; -} -.win-listview .win-horizontal .win-listlayout .win-container { - height: calc(100% - 10px); -} -.win-listview > .win-horizontal .win-surface.win-listlayout.win-headerpositiontop { - -ms-grid-rows: auto 1fr; -} -.win-listview .win-horizontal .win-listlayout.win-headerpositiontop .win-groupheadercontainer { - -ms-grid-row: 1; -} -.win-listview .win-horizontal .win-listlayout.win-headerpositiontop .win-itemscontainer { - -ms-grid-row: 2; -} -.win-listview .win-gridlayout.win-surface { - display: -ms-inline-grid; - vertical-align: top; -} -.win-listview .win-gridlayout .win-container { - margin: 5px; -} -.win-listview .win-vertical .win-gridlayout.win-headerpositionleft .win-groupheadercontainer, -.win-listview .win-vertical .win-gridlayout.win-headerpositiontop .win-groupheadercontainer { - -ms-grid-column: 1; -} -.win-listview.win-groups .win-gridlayout .win-itemscontainer, -.win-listview.win-groups .win-gridlayout .win-groupheadercontainer { - display: none; -} -.win-listview.win-groups .win-gridlayout .win-groupheadercontainer.win-laidout { - display: block; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositiontop.win-surface { - -ms-grid-columns: auto; - -ms-grid-rows: auto 1fr; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositiontop .win-groupheadercontainer { - -ms-grid-row: 1; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositiontop .win-itemscontainer { - -ms-grid-row: 2; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositionleft.win-surface { - -ms-grid-columns: auto; - -ms-grid-rows: auto; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositionleft .win-groupheadercontainer { - -ms-grid-row: 1; -} -.win-listview .win-horizontal .win-gridlayout.win-headerpositionleft .win-itemscontainer { - -ms-grid-row: 1; -} -.win-listview .win-vertical .win-gridlayout.win-headerpositiontop.win-surface { - -ms-grid-columns: auto; - -ms-grid-rows: auto; -} -.win-listview .win-vertical .win-gridlayout.win-headerpositiontop .win-itemscontainer { - -ms-grid-column: 1; -} -.win-listview .win-vertical .win-gridlayout.win-headerpositionleft.win-surface { - -ms-grid-columns: auto 1fr; - -ms-grid-rows: auto; -} -.win-listview .win-vertical .win-gridlayout.win-headerpositionleft .win-itemscontainer { - -ms-grid-column: 2; -} -.win-listview .win-gridlayout.win-structuralnodes .win-uniformgridlayout.win-itemscontainer.win-laidout { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-direction: row; - -webkit-flex-direction: row; - flex-direction: row; -} -.win-listview .win-horizontal .win-listlayout .win-itemscontainer, -.win-listview.win-groups .win-horizontal .win-listlayout .win-itemscontainer.win-laidout, -.win-listview .win-horizontal .win-listlayout .win-itemsblock, -.win-listview .win-horizontal .win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout, -.win-listview .win-horizontal .win-gridlayout .win-uniformgridlayout .win-itemsblock { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-direction: column; - -webkit-flex-direction: column; - flex-direction: column; - -ms-flex-wrap: wrap; - -webkit-flex-wrap: wrap; - flex-wrap: wrap; - -ms-flex-line-pack: start; - -webkit-align-content: flex-start; - align-content: flex-start; -} -.win-listview .win-horizontal .win-itemscontainer-padder { - height: 100%; -} -.win-listview .win-horizontal .win-gridlayout .win-uniformgridlayout .win-itemsblock { - height: 100%; -} -.win-listview .win-horizontal .win-gridlayout .win-cellspanninggridlayout.win-itemscontainer.win-laidout { - display: -ms-grid; -} -.win-listview .win-vertical .win-gridlayout.win-structuralnodes .win-uniformgridlayout.win-itemscontainer.win-laidout { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-direction: column; - -webkit-flex-direction: column; - flex-direction: column; -} -.win-listview .win-vertical .win-gridlayout .win-uniformgridlayout.win-itemscontainer.win-laidout, -.win-listview .win-vertical .win-gridlayout .win-uniformgridlayout .win-itemsblock { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-direction: row; - -webkit-flex-direction: row; - flex-direction: row; - -ms-flex-wrap: wrap; - -webkit-flex-wrap: wrap; - flex-wrap: wrap; - -ms-flex-line-pack: start; - -webkit-align-content: flex-start; - align-content: flex-start; -} -.win-listview .win-vertical .win-gridlayout .win-uniformgridlayout .win-itemsblock { - width: 100%; -} -.win-listview .win-cellspanninggridlayout .win-container.win-laidout { - display: block; -} -.win-listview .win-cellspanninggridlayout .win-container { - display: none; -} -.win-listview .win-itembox { - position: relative; -} -.win-listview.win-dragover .win-itembox { - transform: scale(0.86); - -webkit-transform: scale(0.86); -} -.win-listview .win-itembox.win-dragsource, -.win-itemcontainer .win-itembox.win-dragsource { - opacity: 0.5; - transition: opacity cubic-bezier(0.1, 0.9, 0.2, 1) 167ms, transform cubic-bezier(0.1, 0.9, 0.2, 1) 220ms; - -webkit-transition: opacity cubic-bezier(0.1, 0.9, 0.2, 1) 167ms, transform cubic-bezier(0.1, 0.9, 0.2, 1) 220ms; -} -.win-listview.win-dragover .win-itembox.win-dragsource { - opacity: 0; - transition: none; - -webkit-transition: none; -} -html.win-hoverable .win-listview.win-dragover .win-container:hover { - outline: none; -} -.win-listview .win-itembox { - transition: transform cubic-bezier(0.1, 0.9, 0.2, 1) 220ms; - -webkit-transition: -webkit-transform cubic-bezier(0.1, 0.9, 0.2, 1) 220ms; -} -.win-listview.win-groups > .win-vertical .win-surface.win-listlayout.win-headerpositionleft { - margin-left: 70px; -} -.win-listview.win-groups.win-rtl > .win-vertical .win-surface.win-listlayout.win-headerpositionleft { - margin-left: 0px; - margin-right: 70px; -} -.win-listview > .win-horizontal .win-surface.win-listlayout { - margin-left: 70px; -} -.win-listview.win-rtl > .win-horizontal .win-surface.win-listlayout { - margin-left: 0px; - margin-right: 70px; -} -.win-listview .win-vertical .win-gridlayout.win-surface { - margin-left: 20px; -} -.win-listview.win-rtl .win-vertical .win-gridlayout.win-surface { - margin-left: 0px; - margin-right: 20px; -} -.win-itemcontainer .win-itembox, -.win-itemcontainer.win-container { - position: relative; -} -.win-itemcontainer { - touch-action: pan-x pan-y pinch-zoom; -} -html.win-hoverable .win-listview .win-itembox:hover::before, -html.win-hoverable .win-itemcontainer .win-itembox:hover::before { - opacity: 0.4; -} -html.win-hoverable .win-listview .win-pressed .win-itembox:hover::before, -html.win-hoverable .win-itemcontainer .win-pressed .win-itembox:hover::before, -html.win-hoverable .win-listview .win-pressed.win-itembox:hover::before, -html.win-hoverable .win-itemcontainer .win-pressed.win-itembox:hover::before { - opacity: 0.6; -} -html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover, -html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover, -html.win-hoverable .win-selectionstylefilled .win-itemcontainer.win-container:hover { - outline: none; -} -.win-selectionstylefilled.win-itemcontainer .win-itembox, -.win-selectionstylefilled .win-itemcontainer .win-itembox, -.win-listview.win-selectionstylefilled .win-itembox { - background-color: transparent; -} -.win-listview.win-selectionstylefilled .win-container.win-selected .win-selectionborder, -.win-itemcontainer.win-selectionstylefilled.win-container.win-selected .win-selectionborder { - border-color: transparent; -} -.win-listview.win-selectionstylefilled .win-surface.win-selectionmode .win-itembox::after { - background-color: transparent; -} -.win-listview.win-selectionstylefilled .win-selectioncheckmarkbackground, -.win-itemcontainer.win-selectionstylefilled .win-selectioncheckmarkbackground { - border-color: transparent; -} -.win-listview.win-selectionstylefilled .win-selected a, -.win-listview.win-selectionstylefilled .win-selected progress, -.win-listview.win-selectionstylefilled .win-selected .win-rating .win-star.win-full, -.win-itemcontainer.win-selectionstylefilled.win-selected a, -.win-itemcontainer.win-selectionstylefilled.win-selected progress, -.win-itemcontainer.win-selectionstylefilled.win-selected .win-rating .win-star.win-full { - color: #ffffff; -} -.win-listview.win-selectionstylefilled .win-selected.win-selected a:hover:active, -.win-itemcontainer.win-selectionstylefilled.win-selected.win-selected a:hover:active { - color: rgba(255, 255, 255, 0.6); -} -html.win-hoverable .win-listview.win-selectionstylefilled .win-selected a:hover, -html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-selected a:hover { - color: rgba(255, 255, 255, 0.8); -} -.win-listview.win-selectionstylefilled .win-selected button, -.win-listview.win-selectionstylefilled .win-selected input[type=button], -.win-listview.win-selectionstylefilled .win-selected input[type=reset], -.win-listview.win-selectionstylefilled .win-selected input[type=text], -.win-listview.win-selectionstylefilled .win-selected input[type=password], -.win-listview.win-selectionstylefilled .win-selected input[type=email], -.win-listview.win-selectionstylefilled .win-selected input[type=number], -.win-listview.win-selectionstylefilled .win-selected input[type=tel], -.win-listview.win-selectionstylefilled .win-selected input[type=url], -.win-listview.win-selectionstylefilled .win-selected input[type=search], -.win-listview.win-selectionstylefilled .win-selected input::-ms-check, -.win-listview.win-selectionstylefilled .win-selected textarea, -.win-listview.win-selectionstylefilled .win-selected .win-textarea, -.win-listview.win-selectionstylefilled .win-selected select, -.win-itemcontainer.win-selectionstylefilled.win-selected button, -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=button], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=reset], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=text], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=password], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=email], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=number], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=tel], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=url], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=search], -.win-itemcontainer.win-selectionstylefilled.win-selected input::-ms-check, -.win-itemcontainer.win-selectionstylefilled.win-selected textarea, -.win-itemcontainer.win-selectionstylefilled.win-selected .win-textarea, -.win-itemcontainer.win-selectionstylefilled.win-selected select { - background-clip: border-box; - background-color: rgba(255, 255, 255, 0.8); - border-color: transparent; - color: #000000; -} -.win-listview.win-selectionstylefilled .win-selected button[type=submit], -.win-listview.win-selectionstylefilled .win-selected input[type=submit], -.win-itemcontainer.win-selectionstylefilled.win-selected button[type=submit], -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=submit] { - border-color: #ffffff; -} -.win-listview.win-selectionstylefilled .win-selected input[type=range]::-ms-fill-lower, -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=range]::-ms-fill-lower { - background-color: #ffffff; -} -.win-listview.win-selectionstylefilled .win-selected input[type=range]::-ms-thumb, -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=range]::-ms-thumb { - background-color: #000000; -} -.win-listview.win-selectionstylefilled .win-selected input[type=range]::-ms-fill-upper, -.win-listview.win-selectionstylefilled .win-selected progress, -.win-itemcontainer.win-selectionstylefilled.win-selected input[type=range]::-ms-fill-upper, -.win-itemcontainer.win-selectionstylefilled.win-selected progress { - background-color: rgba(255, 255, 255, 0.16); -} -.win-listview.win-selectionstylefilled .win-selected progress:indeterminate, -.win-itemcontainer.win-selectionstylefilled.win-selected progress:indeterminate { - background-color: transparent; -} -.win-listview.win-selectionstylefilled .win-selected .win-rating .win-star.win-empty, -.win-itemcontainer.win-selectionstylefilled.win-selected .win-rating .win-star.win-empty { - color: rgba(255, 255, 255, 0.16); -} -.win-listview .win-viewport { - outline: none; -} -@media (-ms-high-contrast) { - .win-listview .win-groupheader { - color: WindowText; - } - .win-selectioncheckmark { - color: HighlightText; - } - .win-listview .win-focusedoutline, - .win-listview .win-groupheader, - .win-itemcontainer .win-focusedoutline { - outline-color: WindowText; - } - .win-listview.win-selectionstylefilled .win-itembox, - .win-itemcontainer.win-selectionstylefilled .win-itembox { - background-color: Window; - color: WindowText; - } - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover .win-itembox, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover .win-itembox { - background-color: Highlight; - color: HighlightText; - } - .win-listview.win-selectionstylefilled .win-container.win-selected .win-itembox, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container.win-selected:hover .win-itembox, - .win-itemcontainer.win-selectionstylefilled.win-container.win-selected .win-itembox, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container.win-selected:hover .win-itembox { - background-color: Highlight; - color: HighlightText; - } - .win-listview:not(.win-selectionstylefilled) .win-container.win-selected .win-selectionborder, - .win-itemcontainer:not(.win-selectionstylefilled).win-container.win-selected .win-selectionborder { - border-color: Highlight; - } - .win-listview.win-selectionstylefilled .win-container.win-selected .win-selectionborder, - .win-itemcontainer.win-selectionstylefilled.win-container.win-selected .win-selectionborder { - border-color: transparent; - } - html.win-hoverable .win-listview:not(.win-selectionstylefilled) .win-container.win-selected:hover .win-selectionborder, - html.win-hoverable .win-itemcontainer:not(.win-selectionstylefilled).win-container.win-selected:hover .win-selectionborder { - border-color: Highlight; - } - .win-listview.win-selectionstylefilled .win-selected .win-selectionbackground, - html.win-hoverable .win-listview.win-selectionstylefilled .win-selected:hover .win-selectionbackground, - .win-itemcontainer.win-selectionstylefilled.win-selected .win-selectionbackground, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-selected:hover .win-selectionbackground { - background-color: Highlight; - color: HighlightText; - } - .win-listview.win-selectionstylefilled .win-selectioncheckmarkbackground, - .win-itemcontainer.win-selectionstylefilled .win-selectioncheckmarkbackground { - border-color: transparent; - } - .win-listview.win-selectionstylefilled .win-selected a, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover a, - .win-listview.win-selectionstylefilled .win-selected progress, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover progress, - .win-listview.win-selectionstylefilled .win-selected .win-rating .win-star:after, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover .win-rating .win-star:after, - .win-itemcontainer.win-selectionstylefilled.win-selected a, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover a, - .win-itemcontainer.win-selectionstylefilled.win-selected progress, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover progress, - .win-itemcontainer.win-selectionstylefilled.win-selected .win-rating .win-star:after, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover .win-rating .win-star:after { - color: HighlightText; - } - .win-listview.win-selectionstylefilled .win-selected input, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input, - .win-listview.win-selectionstylefilled .win-selected input::-ms-check, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input::-ms-check, - .win-listview.win-selectionstylefilled .win-selected input::-ms-value, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input::-ms-value, - .win-listview.win-selectionstylefilled .win-selected input::-ms-track, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input::-ms-track, - .win-listview.win-selectionstylefilled .win-selected button, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover button, - .win-listview.win-selectionstylefilled .win-selected progress, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover progress, - .win-listview.win-selectionstylefilled .win-selected progress::-ms-fill, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover progress::-ms-fill, - .win-listview.win-selectionstylefilled .win-selected select, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover select, - .win-listview.win-selectionstylefilled .win-selected textarea, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover textarea, - .win-listview.win-selectionstylefilled.win-selected input, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input, - .win-itemcontainer.win-selectionstylefilled.win-selected input::-ms-check, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input::-ms-check, - .win-itemcontainer.win-selectionstylefilled.win-selected input::-ms-value, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input::-ms-value, - .win-itemcontainer.win-selectionstylefilled.win-selected input::-ms-track, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input::-ms-track, - .win-itemcontainer.win-selectionstylefilled.win-selected button, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover button, - .win-itemcontainer.win-selectionstylefilled.win-selected progress, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover progress, - .win-itemcontainer.win-selectionstylefilled.win-selected progress::-ms-fill, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover progress::-ms-fill, - .win-itemcontainer.win-selectionstylefilled.win-selected select, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover select, - .win-itemcontainer.win-selectionstylefilled.win-selected textarea, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover textarea { - border-color: HighlightText; - } - .win-listview.win-selectionstylefilled .win-selected input[type=range]::-ms-fill-lower, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input[type=range]::-ms-fill-lower, - .win-listview.win-selectionstylefilled .win-selected progress::-ms-fill, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover progress::-ms-fill, - .win-itemcontainer.win-selectionstylefilled.win-selected input[type=range]::-ms-fill-lower, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input[type=range]::-ms-fill-lower, - .win-itemcontainer.win-selectionstylefilled.win-selected progress::-ms-fill, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover progress::-ms-fill { - background-color: HighlightText; - } - .win-listview.win-selectionstylefilled .win-selected input[type=range]::-ms-fill-upper, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover input[type=range]::-ms-fill-upper, - .win-listview.win-selectionstylefilled .win-selected progress, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover progress, - .win-itemcontainer.win-selectionstylefilled.win-selected input[type=range]::-ms-fill-upper, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover input[type=range]::-ms-fill-upper, - .win-itemcontainer.win-selectionstylefilled.win-selected progress, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover progress { - background-color: Highlight; - } - .win-listview.win-selectionstylefilled .win-selected .win-rating .win-star.win-full:before, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover .win-rating .win-star.win-full:before, - .win-itemcontainer.win-selectionstylefilled.win-selected .win-rating .win-star.win-full:before, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover .win-rating .win-star.win-full:before { - color: ButtonFace; - } - .win-listview.win-selectionstylefilled .win-selected .win-rating .win-star.win-empty:before, - html.win-hoverable .win-listview.win-selectionstylefilled .win-container:hover .win-rating .win-star.win-empty:before, - .win-itemcontainer.win-selectionstylefilled.win-selected .win-rating .win-star.win-empty:before, - html.win-hoverable .win-itemcontainer.win-selectionstylefilled.win-container:hover .win-rating .win-star.win-empty:before { - color: Highlight; - } - html.win-hoverable .win-listview .win-container:hover, - html.win-hoverable .win-itemcontainer.win-container:hover { - outline: Highlight solid 3px; - } -} -.win-flipview { - overflow: hidden; - height: 400px; -} -.win-flipview .win-surface { - -ms-scroll-chaining: none; -} -.win-flipview .win-navleft { - left: 0%; - top: 50%; - margin-top: -19px; -} -.win-flipview .win-navright { - left: 100%; - top: 50%; - margin-left: -20px; - margin-top: -19px; -} -.win-flipview .win-navtop { - left: 50%; - top: 0%; - margin-left: -35px; -} -.win-flipview .win-navbottom { - left: 50%; - top: 100%; - margin-left: -35px; - margin-top: -36px; -} -.win-flipview .win-navbutton { - touch-action: manipulation; - border: none; - width: 20px; - height: 36px; - z-index: 1; - position: absolute; - font-family: "Segoe MDL2 Assets", "Symbols"; - font-size: 16px; - padding: 0; - min-width: 0; -} -.win-flipview .win-item, -.win-flipview .win-item > .win-template { - height: 100%; - width: 100%; - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-align: center; - -webkit-align-items: center; - align-items: center; - -ms-flex-pack: center; - -webkit-justify-content: center; - justify-content: center; -} -@media (-ms-high-contrast) { - .win-flipview .win-navbottom { - left: 50%; - top: 100%; - margin-left: -35px; - margin-top: -35px; - } - .win-flipview .win-navbutton { - background-color: ButtonFace; - color: ButtonText; - border: 2px solid ButtonText; - width: 65px; - height: 35px; - } - .win-flipview .win-navbutton.win-navbutton:hover:active, - .win-flipview .win-navbutton.win-navbutton:active { - background-color: ButtonText; - color: ButtonFace; - } - .win-flipview .win-navright { - margin-left: -65px; - } - html.win-hoverable .win-flipview .win-navbutton:hover { - background-color: Highlight; - color: HighlightText; - } -} -.win-datepicker { - display: -ms-inline-flexbox; - display: -webkit-inline-flex; - display: inline-flex; - height: auto; - width: auto; -} -.win-datepicker select { - min-width: 80px; - margin-top: 4px; - margin-bottom: 4px; -} -.win-datepicker .win-datepicker-month { - margin-right: 20px; -} -.win-datepicker .win-datepicker-date.win-order0, -.win-datepicker .win-datepicker-date.win-order1 { - margin-right: 20px; -} -.win-datepicker .win-datepicker-year.win-order0 { - margin-right: 20px; -} -.win-datepicker .win-datepicker-month:lang(ar), -.win-datepicker .win-datepicker-month:lang(dv), -.win-datepicker .win-datepicker-month:lang(fa), -.win-datepicker .win-datepicker-month:lang(he), -.win-datepicker .win-datepicker-month:lang(ku-Arab), -.win-datepicker .win-datepicker-month:lang(pa-Arab), -.win-datepicker .win-datepicker-month:lang(prs), -.win-datepicker .win-datepicker-month:lang(ps), -.win-datepicker .win-datepicker-month:lang(sd-Arab), -.win-datepicker .win-datepicker-month:lang(syr), -.win-datepicker .win-datepicker-month:lang(ug), -.win-datepicker .win-datepicker-month:lang(ur), -.win-datepicker .win-datepicker-month:lang(qps-plocm), -.win-datepicker .win-datepicker-date.win-order0:lang(ar), -.win-datepicker .win-datepicker-date.win-order0:lang(dv), -.win-datepicker .win-datepicker-date.win-order0:lang(fa), -.win-datepicker .win-datepicker-date.win-order0:lang(he), -.win-datepicker .win-datepicker-date.win-order0:lang(ku-Arab), -.win-datepicker .win-datepicker-date.win-order0:lang(pa-Arab), -.win-datepicker .win-datepicker-date.win-order0:lang(prs), -.win-datepicker .win-datepicker-date.win-order0:lang(ps), -.win-datepicker .win-datepicker-date.win-order0:lang(sd-Arab), -.win-datepicker .win-datepicker-date.win-order0:lang(syr), -.win-datepicker .win-datepicker-date.win-order0:lang(ug), -.win-datepicker .win-datepicker-date.win-order0:lang(ur), -.win-datepicker .win-datepicker-date.win-order0:lang(qps-plocm), -.win-datepicker .win-datepicker-date.win-order1:lang(ar), -.win-datepicker .win-datepicker-date.win-order1:lang(dv), -.win-datepicker .win-datepicker-date.win-order1:lang(fa), -.win-datepicker .win-datepicker-date.win-order1:lang(he), -.win-datepicker .win-datepicker-date.win-order1:lang(ku-Arab), -.win-datepicker .win-datepicker-date.win-order1:lang(pa-Arab), -.win-datepicker .win-datepicker-date.win-order1:lang(prs), -.win-datepicker .win-datepicker-date.win-order1:lang(ps), -.win-datepicker .win-datepicker-date.win-order1:lang(sd-Arab), -.win-datepicker .win-datepicker-date.win-order1:lang(syr), -.win-datepicker .win-datepicker-date.win-order1:lang(ug), -.win-datepicker .win-datepicker-date.win-order1:lang(ur), -.win-datepicker .win-datepicker-date.win-order1:lang(qps-plocm), -.win-datepicker .win-datepicker-year.win-order0:lang(ar), -.win-datepicker .win-datepicker-year.win-order0:lang(dv), -.win-datepicker .win-datepicker-year.win-order0:lang(fa), -.win-datepicker .win-datepicker-year.win-order0:lang(he), -.win-datepicker .win-datepicker-year.win-order0:lang(ku-Arab), -.win-datepicker .win-datepicker-year.win-order0:lang(pa-Arab), -.win-datepicker .win-datepicker-year.win-order0:lang(prs), -.win-datepicker .win-datepicker-year.win-order0:lang(ps), -.win-datepicker .win-datepicker-year.win-order0:lang(sd-Arab), -.win-datepicker .win-datepicker-year.win-order0:lang(syr), -.win-datepicker .win-datepicker-year.win-order0:lang(ug), -.win-datepicker .win-datepicker-year.win-order0:lang(ur), -.win-datepicker .win-datepicker-year.win-order0:lang(qps-plocm) { - margin-right: 0; - margin-left: 20px; -} -.win-timepicker { - display: -ms-inline-flexbox; - display: -webkit-inline-flex; - display: inline-flex; - height: auto; - width: auto; -} -.win-timepicker select { - min-width: 80px; - margin-top: 4px; - margin-bottom: 4px; -} -.win-timepicker .win-timepicker-hour { - margin-right: 20px; -} -.win-timepicker .win-timepicker-period.win-order0 { - margin-right: 20px; -} -.win-timepicker .win-timepicker-minute.win-order1 { - margin-right: 20px; -} -.win-timepicker .win-timepicker-period.win-order0:lang(ar), -.win-timepicker .win-timepicker-period.win-order0:lang(dv), -.win-timepicker .win-timepicker-period.win-order0:lang(fa), -.win-timepicker .win-timepicker-period.win-order0:lang(he), -.win-timepicker .win-timepicker-period.win-order0:lang(ku-Arab), -.win-timepicker .win-timepicker-period.win-order0:lang(pa-Arab), -.win-timepicker .win-timepicker-period.win-order0:lang(prs), -.win-timepicker .win-timepicker-period.win-order0:lang(ps), -.win-timepicker .win-timepicker-period.win-order0:lang(sd-Arab), -.win-timepicker .win-timepicker-period.win-order0:lang(syr), -.win-timepicker .win-timepicker-period.win-order0:lang(ug), -.win-timepicker .win-timepicker-period.win-order0:lang(ur), -.win-timepicker .win-timepicker-period.win-order0:lang(qps-plocm), -.win-timepicker .win-timepicker-hour:lang(ar), -.win-timepicker .win-timepicker-hour:lang(dv), -.win-timepicker .win-timepicker-hour:lang(fa), -.win-timepicker .win-timepicker-hour:lang(he), -.win-timepicker .win-timepicker-hour:lang(ku-Arab), -.win-timepicker .win-timepicker-hour:lang(pa-Arab), -.win-timepicker .win-timepicker-hour:lang(prs), -.win-timepicker .win-timepicker-hour:lang(ps), -.win-timepicker .win-timepicker-hour:lang(sd-Arab), -.win-timepicker .win-timepicker-hour:lang(syr), -.win-timepicker .win-timepicker-hour:lang(ug), -.win-timepicker .win-timepicker-hour:lang(ur), -.win-timepicker .win-timepicker-hour:lang(qps-plocm) { - margin-right: 0; - margin-left: 20px; -} -.win-timepicker .win-timepicker-minute.win-order1:lang(ar), -.win-timepicker .win-timepicker-minute.win-order1:lang(dv), -.win-timepicker .win-timepicker-minute.win-order1:lang(fa), -.win-timepicker .win-timepicker-minute.win-order1:lang(he), -.win-timepicker .win-timepicker-minute.win-order1:lang(ku-Arab), -.win-timepicker .win-timepicker-minute.win-order1:lang(pa-Arab), -.win-timepicker .win-timepicker-minute.win-order1:lang(prs), -.win-timepicker .win-timepicker-minute.win-order1:lang(ps), -.win-timepicker .win-timepicker-minute.win-order1:lang(sd-Arab), -.win-timepicker .win-timepicker-minute.win-order1:lang(syr), -.win-timepicker .win-timepicker-minute.win-order1:lang(ug), -.win-timepicker .win-timepicker-minute.win-order1:lang(ur), -.win-timepicker .win-timepicker-minute.win-order1:lang(qps-plocm), -.win-timepicker .win-timepicker-minute.win-order0:lang(ar), -.win-timepicker .win-timepicker-minute.win-order0:lang(dv), -.win-timepicker .win-timepicker-minute.win-order0:lang(fa), -.win-timepicker .win-timepicker-minute.win-order0:lang(he), -.win-timepicker .win-timepicker-minute.win-order0:lang(ku-Arab), -.win-timepicker .win-timepicker-minute.win-order0:lang(pa-Arab), -.win-timepicker .win-timepicker-minute.win-order0:lang(prs), -.win-timepicker .win-timepicker-minute.win-order0:lang(ps), -.win-timepicker .win-timepicker-minute.win-order0:lang(sd-Arab), -.win-timepicker .win-timepicker-minute.win-order0:lang(syr), -.win-timepicker .win-timepicker-minute.win-order0:lang(ug), -.win-timepicker .win-timepicker-minute.win-order0:lang(ur), -.win-timepicker .win-timepicker-minute.win-order0:lang(qps-plocm) { - margin-left: 20px; - margin-right: 0; -} -body > .win-navigation-backbutton { - position: absolute; - top: 50px; - left: 20px; -} -.win-backbutton, -.win-navigation-backbutton, -.win-back { - touch-action: manipulation; - display: inline-block; - min-width: 0; - min-height: 0; - padding: 0; - text-align: center; - width: 41px; - height: 41px; - font-size: 24px; - line-height: 41px; - vertical-align: baseline; -} -.win-backbutton::before, -.win-back::before { - font-family: "Segoe MDL2 Assets", "Symbols"; - font-weight: normal; - content: "\E0D5"; - vertical-align: 50%; -} -.win-backbutton:lang(ar)::before, -.win-backbutton:lang(dv)::before, -.win-backbutton:lang(fa)::before, -.win-backbutton:lang(he)::before, -.win-backbutton:lang(ku-Arab)::before, -.win-backbutton:lang(pa-Arab)::before, -.win-backbutton:lang(prs)::before, -.win-backbutton:lang(ps)::before, -.win-backbutton:lang(sd-Arab)::before, -.win-backbutton:lang(syr)::before, -.win-backbutton:lang(ug)::before, -.win-backbutton:lang(ur)::before, -.win-backbutton:lang(qps-plocm)::before, -.win-back:lang(ar)::before, -.win-back:lang(dv)::before, -.win-back:lang(fa)::before, -.win-back:lang(he)::before, -.win-back:lang(ku-Arab)::before, -.win-back:lang(pa-Arab)::before, -.win-back:lang(prs)::before, -.win-back:lang(ps)::before, -.win-back:lang(sd-Arab)::before, -.win-back:lang(syr)::before, -.win-back:lang(ug)::before, -.win-back:lang(ur)::before, -.win-back:lang(qps-plocm)::before { - content: "\E0AE"; -} -button.win-navigation-backbutton, -button.win-navigation-backbutton:active, -html.win-hoverable button.win-navigation-backbutton:enabled:hover, -button.win-navigation-backbutton:enabled:hover:active { - background-color: transparent; - border: none; -} -@media (-ms-high-contrast) { - button.win-navigation-backbutton, - button.win-navigation-backbutton:active, - html.win-hoverable button.win-navigation-backbutton:enabled:hover, - button.win-navigation-backbutton:enabled:hover:active { - /* Overwrite default background and border styles from BackButton control's ]]> - /// The BackButton control itself - /// The Back Arrow glyph - /// - /// - BackButton: _Base.Namespace._lazy(function () { - // Statics - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/backbuttonarialabel").value; }, - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get badButtonElement() { return "Invalid argument: For a button, toggle, or flyout command, the element must be null or a button element"; } - }; - - var BackButton = _Base.Class.define(function BackButton_ctor(element, options) { - /// - /// - /// Creates a new BackButton control - /// - /// - /// The DOM element that will host the control. If this parameter is null, this constructor creates one for you. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. Each property of the options object corresponds to - /// one of the control's properties or events. - /// - /// - /// A BackButton control. - /// - /// - /// - - // Check to make sure we weren't duplicated - if (element && element.winControl) { - throw new _ErrorFromName("WinJS.UI.BackButton.DuplicateConstruction", strings.duplicateConstruction); - } - - this._element = element || _Global.document.createElement("button"); - options = options || {}; - - this._initializeButton(); // This will also set the aria-label and tooltip - - this._disposed = false; - - // Remember ourselves - this._element.winControl = this; - - _Control.setOptions(this, options); - - // Add event handlers for this back button instance - this._buttonClickHandler = this._handleBackButtonClick.bind(this); - this._element.addEventListener('click', this._buttonClickHandler, false); - this._navigatedHandler = this._handleNavigatedEvent.bind(this); - Navigation.addEventListener('navigated', this._navigatedHandler, false); - - // Increment reference count / manage add global event handlers - singleton.addRef(); - }, { - - /// - element: { - get: function () { - return this._element; - } - }, - - dispose: function () { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; // Mark this control as disposed. - - // Remove 'navigated' eventhandler for this BackButton - Navigation.removeEventListener('navigated', this._navigatedHandler, false); - - singleton.release(); // Decrement reference count. - - }, - - refresh: function () { - /// - /// - /// Sets the 'disabled' attribute to correct the value based on the current navigation history stack. - /// - /// - /// - if (Navigation.canGoBack) { - this._element.disabled = false; - } else { - this._element.disabled = true; - } - }, - - _initializeButton: function () { - //Final EN-US HTML should be: - // - //Button will automatically be disabled if WinJS.Navigation.history.canGoBack is false. - - // Verify the HTML is a button - if (this._element.tagName !== "BUTTON") { - throw new _ErrorFromName("WinJS.UI.BackButton.BadButtonElement", strings.badButtonElement); - } - - // Attach our css classes - _ElementUtilities.addClass(this._element, navigationBackButtonClass); - - // Attach disposable class. - _ElementUtilities.addClass(this._element, "win-disposable"); - - // Create inner glyph element - this._element.innerHTML = ''; - - // Set the 'disabled' property to the correct value based on the current navigation history stack. - this.refresh(); - - // Set Aria-label and native tooltip to the same localized string equivalent of "Back" - this._element.setAttribute("aria-label", strings.ariaLabel); - this._element.setAttribute("title", strings.ariaLabel); - - // Explicitly set type attribute to avoid the default '; - this._headerTabStopElement = this._headerElement.firstElementChild; - // The purpose of headerWrapperElement is to lay out its children in a flexbox. Ideally, this flexbox would - // be on headerTabStopElement. However, firefox lays out flexboxes with display:flex differently. - // Firefox bug 1014285 (Button with display:inline-flex doesn't layout properly) - // https://bugzilla.mozilla.org/show_bug.cgi?id=1014285 - this._headerWrapperElement = this._headerTabStopElement.firstElementChild; - this._headerContentElement = this._headerWrapperElement.firstElementChild; - this._headerChevronElement = this._headerWrapperElement.lastElementChild; - element.appendChild(this._headerElement); - - this._winKeyboard = new _KeyboardBehavior._WinKeyboard(this._headerElement); - - this._contentElement = _Global.document.createElement("DIV"); - this._contentElement.className = HubSection._ClassName.hubSectionContent; - this._contentElement.style.visibility = "hidden"; - element.appendChild(this._contentElement); - - // Reparent any existing elements inside the new hub section content element. - var elementToMove = this.element.firstChild; - while (elementToMove !== this._headerElement) { - var nextElement = elementToMove.nextSibling; - this._contentElement.appendChild(elementToMove); - elementToMove = nextElement; - } - - this._processors = [ControlProcessor.processAll]; - - _Control.setOptions(this, options); - }, { - /// - element: { - get: function () { - return this._element; - } - }, - /// - /// Gets or sets a value that specifies whether the header is static. Set this value to true to disable clicks and other interactions. - /// - /// - isHeaderStatic: { - get: function () { - return this._isHeaderStatic; - }, - set: function (value) { - this._isHeaderStatic = value; - if (!this._isHeaderStatic) { - this._headerTabStopElement.setAttribute("role", "link"); - _ElementUtilities.addClass(this._headerTabStopElement, HubSection._ClassName.hubSectionInteractive); - } else { - this._headerTabStopElement.setAttribute("role", "heading"); - _ElementUtilities.removeClass(this._headerTabStopElement, HubSection._ClassName.hubSectionInteractive); - } - } - }, - /// - /// Gets the DOM element that hosts the HubSection's content. - /// - /// - contentElement: { - get: function () { - return this._contentElement; - } - }, - /// - /// Get or set the HubSection's header. After you set this property, the Hub renders the header again. - /// - /// - header: { - get: function () { - return this._header; - }, - set: function (value) { - // Render again even if it is equal to itself. - this._header = value; - this._renderHeader(); - } - }, - _setHeaderTemplate: function HubSection_setHeaderTemplate(template) { - this._template = _ElementUtilities._syncRenderer(template); - this._renderHeader(); - }, - _renderHeader: function HubSection_renderHeader() { - if (this._template) { - _Dispose._disposeElement(this._headerContentElement); - _ElementUtilities.empty(this._headerContentElement); - this._template(this, this._headerContentElement); - } - }, - _process: function HubSection_process() { - var that = this; - - this._processed = (this._processors || []).reduce(function (promise, processor) { - return promise.then(function () { - return processor(that.contentElement); - }); - }, this._processed || Promise.as()); - this._processors = null; - - return this._processed; - }, - dispose: function HubSection_dispose() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - this._processors = null; - - _Dispose._disposeElement(this._headerContentElement); - _Dispose.disposeSubTree(this.contentElement); - } - }, { - // Names of classes used by the HubSection. - _ClassName: { - hubSection: "win-hub-section", - hubSectionHeader: "win-hub-section-header", - hubSectionHeaderTabStop: "win-hub-section-header-tabstop", - hubSectionHeaderWrapper: "win-hub-section-header-wrapper", - hubSectionInteractive: "win-hub-section-header-interactive", - hubSectionHeaderContent: "win-hub-section-header-content", - hubSectionHeaderChevron: "win-hub-section-header-chevron", - hubSectionContent: "win-hub-section-content" - }, - isDeclarativeControlContainer: _BaseUtils.markSupportedForProcessing(function (section, callback) { - if (callback === ControlProcessor.processAll) { - return; - } - - section._processors = section._processors || []; - section._processors.push(callback); - - // Once processed the first time synchronously queue up new processors as they come in - if (section._processed) { - section._process(); - } - }) - }); - - return HubSection; - }) - }); - -}); - - -define('require-style!less/styles-hub',[],function(){}); - -define('require-style!less/colors-hub',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/Hub',[ - '../Core/_Global', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Events', - '../Core/_Log', - '../Core/_Resources', - '../Core/_WriteProfilerMark', - '../_Accents', - '../Animations', - '../Animations/_TransitionAnimation', - '../BindingList', - '../ControlProcessor', - '../Promise', - '../_Signal', - '../Scheduler', - '../Utilities/_Control', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - '../Utilities/_UI', - './Hub/_Section', - 'require-style!less/styles-hub', - 'require-style!less/colors-hub' -], function hubInit(_Global, _Base, _BaseUtils, _ErrorFromName, _Events, _Log, _Resources, _WriteProfilerMark, _Accents, Animations, _TransitionAnimation, BindingList, ControlProcessor, Promise, _Signal, Scheduler, _Control, _ElementUtilities, _Hoverable, _UI, _Section) { - "use strict"; - - _Accents.createAccentRule( - ".win-semanticzoom-zoomedoutview .win-hub-section-header-interactive .win-hub-section-header-content,\ - .win-hub-section-header-interactive .win-hub-section-header-chevron", - [{ name: "color", value: _Accents.ColorTypes.accent }]); - - _Base.Namespace.define("WinJS.UI", { - /// - /// - /// Displays sections of content. - /// - /// - /// - /// - /// - /// - ///
HubSection Content
- /// ]]>
- /// Raised when the Hub is about to play an entrance or a transition animation. - /// Raised when a header is invoked. - /// Raised when the loading state changes. - /// The entire Hub control. - /// The progress indicator for the Hub. - /// The viewport of the Hub. - /// The scrollable region of the Hub. - /// - /// - Hub: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - function hubDefaultHeaderTemplate(section) { - var element = _Global.document.createTextNode(typeof section.header === "object" ? JSON.stringify(section.header) : ('' + section.header)); - return element; - } - - var createEvent = _Events._createEventProperty; - var eventNames = { - contentAnimating: "contentanimating", - headerInvoked: "headerinvoked", - loadingStateChanged: "loadingstatechanged" - }; - - // Delay time before progress dots are shown when loading hub section(s) on screen. - var progressDelay = 500; - - var verticalNames = { - scrollPos: "scrollTop", - scrollSize: "scrollHeight", - offsetPos: "offsetTop", - offsetSize: "offsetHeight", - oppositeOffsetSize: "offsetWidth", - marginStart: "marginTop", - marginEnd: "marginBottom", - borderStart: "borderTopWidth", - borderEnd: "borderBottomWidth", - paddingStart: "paddingTop", - paddingEnd: "paddingBottom" - }; - var rtlHorizontalNames = { - scrollPos: "scrollLeft", - scrollSize: "scrollWidth", - offsetPos: "offsetLeft", - offsetSize: "offsetWidth", - oppositeOffsetSize: "offsetHeight", - marginStart: "marginRight", - marginEnd: "marginLeft", - borderStart: "borderRightWidth", - borderEnd: "borderLeftWidth", - paddingStart: "paddingRight", - paddingEnd: "paddingLeft" - }; - var ltrHorizontalNames = { - scrollPos: "scrollLeft", - scrollSize: "scrollWidth", - offsetPos: "offsetLeft", - offsetSize: "offsetWidth", - oppositeOffsetSize: "offsetHeight", - marginStart: "marginLeft", - marginEnd: "marginRight", - borderStart: "borderLeftWidth", - borderEnd: "borderRightWidth", - paddingStart: "paddingLeft", - paddingEnd: "paddingRight" - }; - - var Hub = _Base.Class.define(function Hub_ctor(element, options) { - /// - /// - /// Creates a new Hub control. - /// - /// - /// The DOM element that hosts the Hub control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the contentanimating event, - /// add a property named "oncontentanimating" to the options object and set its value to the event handler. - /// - /// - /// The new Hub. - /// - /// - /// - element = element || _Global.document.createElement("DIV"); - options = options || {}; - - if (element.winControl) { - throw new _ErrorFromName("WinJS.UI.Hub.DuplicateConstruction", strings.duplicateConstruction); - } - - this._id = element.id || _ElementUtilities._uniqueID(element); - this._writeProfilerMark("constructor,StartTM"); - - this._windowKeyDownHandlerBound = this._windowKeyDownHandler.bind(this); - _Global.addEventListener('keydown', this._windowKeyDownHandlerBound); - - // Attaching JS control to DOM element - element.winControl = this; - this._element = element; - _ElementUtilities.addClass(this.element, Hub._ClassName.hub); - _ElementUtilities.addClass(this.element, "win-disposable"); - - this._viewportElement = _Global.document.createElement("DIV"); - this._viewportElement.className = Hub._ClassName.hubViewport; - this._element.appendChild(this._viewportElement); - this._viewportElement.setAttribute("role", "group"); - this._viewportElement.setAttribute("aria-label", strings.hubViewportAriaLabel); - - this._surfaceElement = _Global.document.createElement("DIV"); - this._surfaceElement.className = Hub._ClassName.hubSurface; - this._viewportElement.appendChild(this._surfaceElement); - - // Start invisible so that you do not see the content loading until the sections are ready. - this._visible = false; - this._viewportElement.style.opacity = 0; - - if (!options.orientation) { - this._orientation = _UI.Orientation.horizontal; - _ElementUtilities.addClass(this.element, Hub._ClassName.hubHorizontal); - } - - this._fireEntrance = true; - this._animateEntrance = true; - this._loadId = 0; - this.runningAnimations = new Promise.wrap(); - this._currentIndexForSezo = 0; - - // This internally assigns this.sections which causes section to be used (even from options) before - // scrollPosition or sectionOnScreen. - this._parse(); - - _Control.setOptions(this, options); - - _ElementUtilities._addEventListener(this.element, "focusin", this._focusin.bind(this), false); - this.element.addEventListener("keydown", this._keyDownHandler.bind(this)); - this.element.addEventListener("click", this._clickHandler.bind(this)); - this._resizeHandlerBound = this._resizeHandler.bind(this); - this.element.addEventListener("mselementresize", this._resizeHandlerBound); - _ElementUtilities._resizeNotifier.subscribe(this.element, this._resizeHandlerBound); - this._viewportElement.addEventListener("scroll", this._scrollHandler.bind(this)); - this._surfaceElement.addEventListener("mselementresize", this._contentResizeHandler.bind(this)); - - this._handleSectionChangedBind = this._handleSectionChanged.bind(this); - this._handleSectionInsertedBind = this._handleSectionInserted.bind(this); - this._handleSectionMovedBind = this._handleSectionMoved.bind(this); - this._handleSectionRemovedBind = this._handleSectionRemoved.bind(this); - this._handleSectionReloadBind = this._handleSectionReload.bind(this); - - this._refresh(); - - this._writeProfilerMark("constructor,StopTM"); - }, { - /// - element: { - get: function () { - return this._element; - } - }, - /// - /// Gets or sets the orientation of sections within the Hub. - /// - /// - orientation: { - get: function () { - return this._orientation; - }, - set: function (value) { - if (value === this._orientation) { - return; - } - this._measured = false; - // clear existing scroll before we switch orientation - if (this._names) { // handle setting orientation before we measure - var newScrollPos = {}; - newScrollPos[this._names.scrollPos] = 0; - _ElementUtilities.setScrollPosition(this._viewportElement, newScrollPos); - } - if (value === _UI.Orientation.vertical) { - _ElementUtilities.removeClass(this.element, Hub._ClassName.hubHorizontal); - _ElementUtilities.addClass(this.element, Hub._ClassName.hubVertical); - } else { - value = _UI.Orientation.horizontal; - _ElementUtilities.removeClass(this.element, Hub._ClassName.hubVertical); - _ElementUtilities.addClass(this.element, Hub._ClassName.hubHorizontal); - } - this._orientation = value; - Scheduler.schedule(this._updateSnapList.bind(this), Scheduler.Priority.idle); - } - }, - /// - /// Gets or sets the WinJS.Binding.List of HubSection objects that belong to this Hub. - /// - /// - sections: { - get: function () { - if (this._pendingSections) { - return this._pendingSections; - } - return this._sections; - }, - set: function (value) { - var resetScrollPosition = !this._pendingSections; - this._pendingSections = value; - this._refresh(); - if (resetScrollPosition) { - this.scrollPosition = 0; - } - } - }, - /// - /// Gets or sets the WinJS.Binding.Template or template function that creates the DOM elements - /// which represent the header for each HubSection. Each header can - /// contain multiple DOM elements, but we recommend that it have a single - /// root element. - /// - /// - headerTemplate: { - get: function () { - if (this._pendingHeaderTemplate) { - return this._pendingHeaderTemplate; - } - - if (!this._headerTemplate) { - this._headerTemplate = hubDefaultHeaderTemplate; - } - - return this._headerTemplate; - }, - set: function (value) { - this._pendingHeaderTemplate = value || hubDefaultHeaderTemplate; - this._refresh(); - } - }, - /// - /// Gets or sets the position of the Hub's scrollbar. - /// - /// - scrollPosition: { - get: function () { - if (+this._pendingScrollLocation === this._pendingScrollLocation) { - return this._pendingScrollLocation; - } - - this._measure(); - return this._scrollPosition; - }, - set: function (value) { - value = Math.max(0, value); - if (this._pendingRefresh) { - // Unable to constrain length because sections may have changed. - this._pendingScrollLocation = value; - this._pendingSectionOnScreen = null; - } else { - this._measure(); - var targetScrollPos = Math.max(0, Math.min(this._scrollLength - this._viewportSize, value)); - this._scrollPosition = targetScrollPos; - var newScrollPos = {}; - newScrollPos[this._names.scrollPos] = targetScrollPos; - _ElementUtilities.setScrollPosition(this._viewportElement, newScrollPos); - } - } - }, - - /// - /// Gets or sets the index of first section in view. This property is useful for restoring a previous view when your app launches or resumes. - /// - /// - sectionOnScreen: { - get: function () { - if (+this._pendingSectionOnScreen === this._pendingSectionOnScreen) { - return this._pendingSectionOnScreen; - } - - this._measure(); - for (var i = 0; i < this._sectionSizes.length; i++) { - var sectionSize = this._sectionSizes[i]; - if ((sectionSize.offset + sectionSize.size - sectionSize.borderEnd - sectionSize.paddingEnd) > (this._scrollPosition + this._startSpacer + sectionSize.borderStart + sectionSize.paddingStart)) { - return i; - } - } - return -1; - }, - set: function (value) { - value = Math.max(0, value); - if (this._pendingRefresh) { - this._pendingSectionOnScreen = value; - this._pendingScrollLocation = null; - } else { - this._measure(); - if (value >= 0 && value < this._sectionSizes.length) { - this._scrollToSection(value); - } - } - } - }, - /// - /// Gets or sets the index of first section at least partially in view. Use for animations. - /// - /// - indexOfFirstVisible: { - get: function () { - this._measure(); - for (var i = 0; i < this._sectionSizes.length; i++) { - var sectionSize = this._sectionSizes[i]; - if ((sectionSize.offset + sectionSize.size - sectionSize.borderEnd - sectionSize.paddingEnd) > this._scrollPosition) { - return i; - } - } - return -1; - } - }, - /// - /// Gets or sets the index of last section at least partially in view. Use for animations. - /// - /// - indexOfLastVisible: { - get: function () { - this._measure(); - for (var i = this._sectionSizes.length - 1; i >= 0; i--) { - var sectionSize = this._sectionSizes[i]; - if ((sectionSize.offset + sectionSize.paddingStart + sectionSize.borderStart) < (this._scrollPosition + this._viewportSize)) { - return i; - } - } - return -1; - } - }, - - /// - /// Raised when the user clicks on an interactive header. - /// - /// - onheaderinvoked: createEvent(eventNames.headerInvoked), - - /// - /// Raised when the loadingState of the Hub changes. - /// - /// - onloadingstatechanged: createEvent(eventNames.loadingStateChanged), - - /// - /// Raised when Hub is about to play entrance, contentTransition, insert, or remove animations. - /// - /// - oncontentanimating: createEvent(eventNames.contentAnimating), - - _refresh: function hub_refresh() { - if (this._pendingRefresh) { - return; - } - - this._loadId++; - this._setState(Hub.LoadingState.loading); - // This is to coalesce property setting operations such as sections and scrollPosition. - this._pendingRefresh = true; - - Scheduler.schedule(this._refreshImpl.bind(this), Scheduler.Priority.high); - }, - _refreshImpl: function hub_refreshImpl() { - if (this._disposed) { - return; - } - - var fadeOutAnimation = Promise.wrap(); - if (this._pendingSections) { - this._animateEntrance = true; - this._fireEntrance = !this._visible; - if (!this._fireEntrance) { - this._visible = false; - this._viewportElement.style.opacity = 0; - - if (_TransitionAnimation.isAnimationEnabled()) { - var animateTransition = this._fireEvent(Hub._EventName.contentAnimating, { - type: Hub.AnimationType.contentTransition - }); - - if (animateTransition) { - this._viewportElement.style["-ms-overflow-style"] = "none"; - fadeOutAnimation = Animations.fadeOut(this._viewportElement).then(function () { - this._viewportElement.style["-ms-overflow-style"] = ""; - }.bind(this)); - } - this._animateEntrance = animateTransition; - } - } - } - - fadeOutAnimation.done(this._applyProperties.bind(this)); - }, - _applyProperties: function hub_applyProperties() { - if (this._disposed) { - return; - } - - this._pendingRefresh = false; - - var needsToLoadSections = false; - if (this._pendingSections) { - needsToLoadSections = true; - this._updateEvents(this._sections, this._pendingSections); - this._sections = this._pendingSections; - this._pendingSections = null; - // Remove any declaratively specified hub sections before attachSections. - while (this.element.firstElementChild !== this._viewportElement) { - var toRemove = this.element.firstElementChild; - toRemove.parentNode.removeChild(toRemove); - } - _ElementUtilities.empty(this._surfaceElement); - } - - if (this._pendingHeaderTemplate) { - this._headerTemplate = this._pendingHeaderTemplate; - this._pendingHeaderTemplate = null; - } - - this._assignHeaderTemplate(); - - if (needsToLoadSections) { - this._attachSections(); - } - - // Scroll after headers are rendered and sections are attached so the scroll thumb is correct. - if (+this._pendingSectionOnScreen === this._pendingSectionOnScreen) { - // If there are both pending section on screen and scroll location use section on screen. - this.sectionOnScreen = this._pendingSectionOnScreen; - } else if (+this._pendingScrollLocation === this._pendingScrollLocation) { - this.scrollPosition = this._pendingScrollLocation; - } else { - // Sections reset without sectionOnScreen or scrollPosition APIs. - this.scrollPosition = 0; - } - - this._pendingSectionOnScreen = null; - this._pendingScrollLocation = null; - - // Using current (or new) scroll location load the sections - this._setState(Hub.LoadingState.loading); - this._loadSections(); - }, - _handleSectionChanged: function hub_handleSectionChanged(ev) { - // Change is triggered by binding list setAt() API. - if (this._pendingSections) { - return; - } - - var newSection = ev.detail.newValue; - var oldSection = ev.detail.oldValue; - newSection._setHeaderTemplate(this.headerTemplate); - if (newSection.element !== oldSection.element) { - if (newSection.element.parentNode === this._surfaceElement) { - throw new _ErrorFromName("WinJS.UI.Hub.DuplicateSection", strings.duplicateSection); - } - - this._surfaceElement.insertBefore(newSection.element, oldSection.element); - this._surfaceElement.removeChild(oldSection.element); - this._measured = false; - - this._setState(Hub.LoadingState.loading); - this._loadSections(); - } - }, - _handleSectionInserted: function hub_handleSectionInserted(ev) { - // Insert is triggered by binding list insert APIs such as splice(), push(), and unshift(). - if (this._pendingSections) { - return; - } - - var index = ev.detail.index; - var section = ev.detail.value; - - if (section._animation) { - section._animation.cancel(); - } - - var animation; - var result = this._fireEvent(Hub._EventName.contentAnimating, { - type: Hub.AnimationType.insert, - index: index, - section: section - }); - - if (result) { - - var affectedElements = []; - - for (var i = index + 1; i < this.sections.length; i++) { - affectedElements.push(this.sections.getAt(i).element); - } - - animation = new Animations._createUpdateListAnimation([section.element], [], affectedElements); - } - - if (section.element.parentNode === this._surfaceElement) { - throw new _ErrorFromName("WinJS.UI.Hub.DuplicateSection", strings.duplicateSection); - } - - section._setHeaderTemplate(this.headerTemplate); - if (index < this.sections.length - 1) { - this._surfaceElement.insertBefore(section.element, this.sections.getAt(index + 1).element); - } else { - this._surfaceElement.appendChild(section.element); - } - this._measured = false; - - if (animation) { - var insertAnimation = animation.execute(); - this.runningAnimations = Promise.join([this.runningAnimations, insertAnimation]); - } - - this._setState(Hub.LoadingState.loading); - this._loadSections(); - }, - _handleSectionMoved: function hub_handleSectionMoved(ev) { - // Move is triggered by binding list move() API. - if (this._pendingSections) { - return; - } - - var newIndex = ev.detail.newIndex; - var section = ev.detail.value; - - if (newIndex < this.sections.length - 1) { - this._surfaceElement.insertBefore(section.element, this.sections.getAt(newIndex + 1).element); - } else { - this._surfaceElement.appendChild(section.element); - } - this._measured = false; - - this._setState(Hub.LoadingState.loading); - this._loadSections(); - }, - _handleSectionRemoved: function hub_handleSectionRemoved(ev) { - // Removed is triggered by binding list removal APIs such as splice(), pop(), and shift(). - if (this._pendingSections) { - return; - } - - var section = ev.detail.value; - var index = ev.detail.index; - - var animationPromise = Promise.wrap(); - var result = this._fireEvent(Hub._EventName.contentAnimating, { - type: Hub.AnimationType.remove, - index: index, - section: section - }); - - if (result) { - var affectedElements = []; - - for (var i = index; i < this.sections.length; i++) { - affectedElements.push(this.sections.getAt(i).element); - } - - var animation = new Animations._createUpdateListAnimation([], [section.element], affectedElements); - - this._measure(); - var offsetTop = section.element.offsetTop; - var offsetLeft = section.element.offsetLeft; - section.element.style.position = "absolute"; - section.element.style.top = offsetTop; - section.element.style.left = offsetLeft; - section.element.style.opacity = 0; - this._measured = false; - - animationPromise = animation.execute().then(function () { - section.element.style.position = ""; - section.element.style.top = ""; - section.element.style.left = ""; - section.element.style.opacity = 1; - }.bind(this)); - } - - animationPromise.done(function () { - if (!this._disposed) { - this._surfaceElement.removeChild(section.element); - this._measured = false; - } - }.bind(this)); - - // Store animation promise in case it is inserted before remove animation finishes. - section._animation = animationPromise; - this.runningAnimations = Promise.join([this.runningAnimations, animationPromise]); - - this._setState(Hub.LoadingState.loading); - this._loadSections(); - }, - _handleSectionReload: function hub_handleSectionReload() { - // Reload is triggered by large operations on the binding list such as reverse(). This causes - // _pendingSections to be true which ignores future insert/remove/modified/moved events until the new - // sections list is applied. - this.sections = this.sections; - }, - _updateEvents: function hub_updateEvents(oldSections, newSections) { - if (oldSections) { - oldSections.removeEventListener("itemchanged", this._handleSectionChangedBind); - oldSections.removeEventListener("iteminserted", this._handleSectionInsertedBind); - oldSections.removeEventListener("itemmoved", this._handleSectionMovedBind); - oldSections.removeEventListener("itemremoved", this._handleSectionRemovedBind); - oldSections.removeEventListener("reload", this._handleSectionReloadBind); - } - - if (newSections) { - newSections.addEventListener("itemchanged", this._handleSectionChangedBind); - newSections.addEventListener("iteminserted", this._handleSectionInsertedBind); - newSections.addEventListener("itemmoved", this._handleSectionMovedBind); - newSections.addEventListener("itemremoved", this._handleSectionRemovedBind); - newSections.addEventListener("reload", this._handleSectionReloadBind); - } - }, - _attachSections: function hub_attachSections() { - this._measured = false; - for (var i = 0; i < this.sections.length; i++) { - var section = this._sections.getAt(i); - if (section._animation) { - section._animation.cancel(); - } - if (section.element.parentNode === this._surfaceElement) { - throw new _ErrorFromName("WinJS.UI.Hub.DuplicateSection", strings.duplicateSection); - } - this._surfaceElement.appendChild(section.element); - } - }, - _assignHeaderTemplate: function hub_assignHeaderTemplate() { - this._measured = false; - for (var i = 0; i < this.sections.length; i++) { - var section = this._sections.getAt(i); - section._setHeaderTemplate(this.headerTemplate); - } - }, - _loadSection: function hub_loadSection(index) { - var section = this._sections.getAt(index); - return section._process().then(function resetVisibility() { - var style = section.contentElement.style; - if (style.visibility !== "") { - style.visibility = ""; - } - }); - }, - _loadSections: function hub_loadSections() { - // Used to know if another load has interrupted this one. - this._loadId++; - var loadId = this._loadId; - var that = this; - var onScreenItemsAnimatedPromise = Promise.wrap(); - var sectionIndicesToLoad = []; - var allSectionsLoadedPromise = Promise.wrap(); - - function loadNextSectionAfterPromise(promise) { - promise.then(function () { - Scheduler.schedule(loadNextSection, Scheduler.Priority.idle); - }); - } - - function loadNextSection() { - if (loadId === that._loadId && !that._disposed) { - if (sectionIndicesToLoad.length) { - var index = sectionIndicesToLoad.shift(); - var loadedPromise = that._loadSection(index); - loadNextSectionAfterPromise(loadedPromise); - } else { - allSectionsLoadedSignal.complete(); - } - } - } - - if (!this._showProgressPromise) { - this._showProgressPromise = Promise.timeout(progressDelay).then(function () { - if (this._disposed) { - return; - } - - if (!this._progressBar) { - this._progressBar = _Global.document.createElement("progress"); - _ElementUtilities.addClass(this._progressBar, Hub._ClassName.hubProgress); - this._progressBar.max = 100; - } - if (!this._progressBar.parentNode) { - this.element.insertBefore(this._progressBar, this._viewportElement); - } - this._showProgressPromise = null; - }.bind(this), function () { - this._showProgressPromise = null; - }.bind(this)); - } - - if (this.sections.length) { - var allSectionsLoadedSignal = new _Signal(); - allSectionsLoadedPromise = allSectionsLoadedSignal.promise; - // Synchronously load the sections on screen. - var synchronousProcessPromises = []; - var start = Math.max(0, this.indexOfFirstVisible); - var end = Math.max(0, this.indexOfLastVisible); - for (var i = start; i <= end; i++) { - synchronousProcessPromises.push(this._loadSection(i)); - } - - // Determine the order to load the rest of the sections. - start--; - end++; - while (start >= 0 || end < this.sections.length) { - if (end < this.sections.length) { - sectionIndicesToLoad.push(end); - end++; - } - if (start >= 0) { - sectionIndicesToLoad.push(start); - start--; - } - } - - var onScreenSectionsLoadedPromise = Promise.join(synchronousProcessPromises); - - // In case there are overlapping load calls - onScreenSectionsLoadedPromise.done(function () { - if (loadId === this._loadId && !that._disposed) { - if (this._showProgressPromise) { - this._showProgressPromise.cancel(); - } - - if (this._progressBar && this._progressBar.parentNode) { - this._progressBar.parentNode.removeChild(this._progressBar); - } - - Scheduler.schedule(function Hub_entranceAnimation() { - if (loadId === this._loadId && !that._disposed) { - if (!this._visible) { - this._visible = true; - this._viewportElement.style.opacity = 1; - - if (this._animateEntrance && _TransitionAnimation.isAnimationEnabled()) { - var eventDetail = { - type: Hub.AnimationType.entrance - }; - - if (!this._fireEntrance || this._fireEvent(Hub._EventName.contentAnimating, eventDetail)) { - this._viewportElement.style["-ms-overflow-style"] = "none"; - onScreenItemsAnimatedPromise = Animations.enterContent(this._viewportElement).then(function () { - this._viewportElement.style["-ms-overflow-style"] = ""; - }.bind(this)); - } - } - if (this._element === _Global.document.activeElement) { - this._moveFocusIn(this.sectionOnScreen); - } - } - } - }, Scheduler.Priority.high, this, "WinJS.UI.Hub.entranceAnimation"); - } - }.bind(this)); - - loadNextSectionAfterPromise(onScreenSectionsLoadedPromise); - } else { - if (this._showProgressPromise) { - this._showProgressPromise.cancel(); - } - - if (this._progressBar && this._progressBar.parentNode) { - this._progressBar.parentNode.removeChild(this._progressBar); - } - } - - Promise.join([this.runningAnimations, onScreenItemsAnimatedPromise, allSectionsLoadedPromise]).done(function () { - if (loadId === this._loadId && !that._disposed) { - this.runningAnimations = Promise.wrap(); - if (this._measured && this._scrollLength !== this._viewportElement[this._names.scrollSize]) { - // A section changed size during processing. Invalidate the Hub's measurements so that its - // API's work correctly within the loadingState=complete handler. - this._measured = false; - } - this._setState(Hub.LoadingState.complete); - Scheduler.schedule(this._updateSnapList.bind(this), Scheduler.Priority.idle); - } - }.bind(this)); - }, - /// - loadingState: { - get: function () { - return this._loadingState; - } - }, - _setState: function Hub_setState(state) { - if (state !== this._loadingState) { - this._writeProfilerMark("loadingStateChanged:" + state + ",info"); - this._loadingState = state; - var eventObject = _Global.document.createEvent("CustomEvent"); - eventObject.initCustomEvent(Hub._EventName.loadingStateChanged, true, false, { loadingState: state }); - this._element.dispatchEvent(eventObject); - } - }, - _parse: function hub_parse() { - var hubSections = []; - var hubSectionEl = this.element.firstElementChild; - - while (hubSectionEl !== this._viewportElement) { - ControlProcessor.processAll(hubSectionEl); - - var hubSectionContent = hubSectionEl.winControl; - if (hubSectionContent) { - hubSections.push(hubSectionContent); - } else { - throw new _ErrorFromName("WinJS.UI.Hub.InvalidContent", strings.invalidContent); - } - - var nextSectionEl = hubSectionEl.nextElementSibling; - hubSectionEl = nextSectionEl; - } - - this.sections = new BindingList.List(hubSections); - }, - _fireEvent: function hub_fireEvent(type, detail) { - // Returns true if ev.preventDefault() was not called - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(type, true, true, detail); - return this.element.dispatchEvent(event); - }, - - _findHeaderTabStop: function hub_findHeaderTabStop(element) { - if (element.parentNode) { - if (_ElementUtilities._matchesSelector(element, ".win-hub-section-header-tabstop, .win-hub-section-header-tabstop *")) { - while (!_ElementUtilities.hasClass(element, "win-hub-section-header-tabstop")) { - element = element.parentElement; - } - return element; - } - } - return null; - }, - _isInteractive: function hub_isInteractive(element) { - // Helper method to skip keyboarding and clicks - - while (element && element !== _Global.document.body) { - if (element.classList.contains("win-interactive")) { - return true; - } - element = element.parentElement; - } - return false; - }, - _clickHandler: function hub_clickHandler(ev) { - var headerTabStopElement = this._findHeaderTabStop(ev.target); - if (headerTabStopElement && !this._isInteractive(ev.target)) { - var section = headerTabStopElement.parentElement.parentElement.winControl; - if (!section.isHeaderStatic) { - var sectionIndex = this.sections.indexOf(section); - this._fireEvent(Hub._EventName.headerInvoked, { - index: sectionIndex, - section: section - }); - } - } - }, - _resizeHandler: function hub_resizeHandler() { - // Viewport needs to be measured - this._measured = false; - Scheduler.schedule(this._updateSnapList.bind(this), Scheduler.Priority.idle); - }, - _contentResizeHandler: function hub_contentResizeHandler() { - // Sections and scroll length need to be measured - this._measured = false; - Scheduler.schedule(this._updateSnapList.bind(this), Scheduler.Priority.idle); - }, - _scrollHandler: function hub_scrollHandler() { - // Scroll location needs to be retrieved - this._measured = false; - - if (this._pendingSections) { - return; - } - - // Scroll events caused by users overwrite pending API modifications to scrollposition. - this._pendingScrollLocation = null; - this._pendingSectionOnScreen = null; - - if (!this._pendingScrollHandler) { - this._pendingScrollHandler = _BaseUtils._requestAnimationFrame(function () { - this._pendingScrollHandler = null; - - if (this._pendingSections) { - return; - } - - if (this.loadingState !== Hub.LoadingState.complete) { - this._loadSections(); - } - }.bind(this)); - } - }, - _measure: function hub_measure() { - // Any time a size changes (section growing, window resizing, etc) cachedSizes should be set to false - // and any time the variables need to be read again we should measure the variables. To avoid a lot of - // seperate layouts we measure the variables in a single batch. - if (!this._measured || this._scrollLength === 0) { - this._writeProfilerMark("measure,StartTM"); - this._measured = true; - - this._rtl = _Global.getComputedStyle(this._element, null).direction === "rtl"; - - if (this.orientation === _UI.Orientation.vertical) { - this._names = verticalNames; - } else { - if (this._rtl) { - this._names = rtlHorizontalNames; - } else { - this._names = ltrHorizontalNames; - } - } - - this._viewportSize = this._viewportElement[this._names.offsetSize]; - this._viewportOppositeSize = this._viewportElement[this._names.oppositeOffsetSize]; - this._scrollPosition = _ElementUtilities.getScrollPosition(this._viewportElement)[this._names.scrollPos]; - this._scrollLength = this._viewportElement[this._names.scrollSize]; - - var surfaceElementComputedStyle = _Global.getComputedStyle(this._surfaceElement); - this._startSpacer = parseFloat(surfaceElementComputedStyle[this._names.marginStart]) + parseFloat(surfaceElementComputedStyle[this._names.borderStart]) + parseFloat(surfaceElementComputedStyle[this._names.paddingStart]); - this._endSpacer = parseFloat(surfaceElementComputedStyle[this._names.marginEnd]) + parseFloat(surfaceElementComputedStyle[this._names.borderEnd]) + parseFloat(surfaceElementComputedStyle[this._names.paddingEnd]); - - this._sectionSizes = []; - for (var i = 0; i < this.sections.length; i++) { - var section = this.sections.getAt(i); - var computedSectionStyle = _Global.getComputedStyle(section.element); - this._sectionSizes[i] = { - offset: section.element[this._names.offsetPos], - // Reminder: offsetWidth doesn't include margins and also rounds. - size: section.element[this._names.offsetSize], - marginStart: parseFloat(computedSectionStyle[this._names.marginStart]), - marginEnd: parseFloat(computedSectionStyle[this._names.marginEnd]), - borderStart: parseFloat(computedSectionStyle[this._names.borderStart]), - borderEnd: parseFloat(computedSectionStyle[this._names.borderEnd]), - paddingStart: parseFloat(computedSectionStyle[this._names.paddingStart]), - paddingEnd: parseFloat(computedSectionStyle[this._names.paddingEnd]) - }; - - if (this._rtl && this.orientation === _UI.Orientation.horizontal) { - this._sectionSizes[i].offset = this._viewportSize - (this._sectionSizes[i].offset + this._sectionSizes[i].size); - } - } - - this._writeProfilerMark("measure,StopTM"); - } - }, - _updateSnapList: function hub_updateSnapList() { - this._writeProfilerMark("updateSnapList,StartTM"); - this._measure(); - - var snapList = "snapList("; - for (var i = 0; i < this._sectionSizes.length; i++) { - if (i > 0) { - snapList += ","; - } - var sectionSize = this._sectionSizes[i]; - snapList += (sectionSize.offset - sectionSize.marginStart - this._startSpacer) + "px"; - } - snapList += ")"; - - var snapListY = ""; - var snapListX = ""; - if (this.orientation === _UI.Orientation.vertical) { - snapListY = snapList; - } else { - snapListX = snapList; - } - - if (this._lastSnapPointY !== snapListY) { - this._lastSnapPointY = snapListY; - this._viewportElement.style['-ms-scroll-snap-points-y'] = snapListY; - } - - if (this._lastSnapPointX !== snapListX) { - this._lastSnapPointX = snapListX; - this._viewportElement.style['-ms-scroll-snap-points-x'] = snapListX; - } - - this._writeProfilerMark("updateSnapList,StopTM"); - }, - _scrollToSection: function Hub_scrollToSection(index, withAnimation) { - this._measure(); - var sectionSize = this._sectionSizes[index]; - var scrollPositionToShowStartMargin = Math.min(this._scrollLength - this._viewportSize, sectionSize.offset - sectionSize.marginStart - this._startSpacer); - - this._scrollTo(scrollPositionToShowStartMargin, withAnimation); - }, - _ensureVisible: function hub_ensureVisible(index, withAnimation) { - this._measure(); - var targetScrollPos = this._ensureVisibleMath(index, this._scrollPosition); - this._scrollTo(targetScrollPos, withAnimation); - }, - _ensureVisibleMath: function hub_ensureVisibleMath(index, targetScrollPos) { - this._measure(); - var sectionSize = this._sectionSizes[index]; - - var scrollPositionToShowStartMargin = Math.min(this._scrollLength - this._viewportSize, sectionSize.offset - sectionSize.marginStart - this._startSpacer); - var scrollPositionToShowEndMargin = Math.max(0, sectionSize.offset + sectionSize.size + sectionSize.marginEnd + this._endSpacer - this._viewportSize + 1); - if (targetScrollPos > scrollPositionToShowStartMargin) { - targetScrollPos = scrollPositionToShowStartMargin; - } else if (targetScrollPos < scrollPositionToShowEndMargin) { - targetScrollPos = Math.min(scrollPositionToShowStartMargin, scrollPositionToShowEndMargin); - } - - return targetScrollPos; - }, - _scrollTo: function hub_scrollTo(scrollPos, withAnimation) { - this._scrollPosition = scrollPos; - if (withAnimation) { - if (this.orientation === _UI.Orientation.vertical) { - _ElementUtilities._zoomTo(this._viewportElement, { contentX: 0, contentY: this._scrollPosition, viewportX: 0, viewportY: 0 }); - } else { - _ElementUtilities._zoomTo(this._viewportElement, { contentX: this._scrollPosition, contentY: 0, viewportX: 0, viewportY: 0 }); - } - } else { - var newScrollPos = {}; - newScrollPos[this._names.scrollPos] = this._scrollPosition; - _ElementUtilities.setScrollPosition(this._viewportElement, newScrollPos); - } - }, - _windowKeyDownHandler: function hub_windowKeyDownHandler(ev) { - // Include tab and shift tab. Note: Alt Key + Tab and Windows Key + Tab do not fire keydown with ev.key === "Tab". - if (ev.keyCode === Key.tab) { - this._tabSeenLast = true; - - var that = this; - _BaseUtils._yieldForEvents(function () { - that._tabSeenLast = false; - }); - } - }, - _focusin: function hub_focusin(ev) { - // On focus we call ensureVisible to handle the tab or shift/tab to header. However if the - // focus was caused by a pointer down event we skip the focus. - if (this._tabSeenLast) { - var headerTabStopElement = this._findHeaderTabStop(ev.target); - if (headerTabStopElement && !this._isInteractive(ev.target)) { - var sectionIndex = this.sections.indexOf(headerTabStopElement.parentElement.parentElement.winControl); - if (sectionIndex > -1) { - this._ensureVisible(sectionIndex, true); - } - } - } - - // Always remember the focused section for SemanticZoom. - var sectionElement = ev.target; - while (sectionElement && !_ElementUtilities.hasClass(sectionElement, _Section.HubSection._ClassName.hubSection)) { - sectionElement = sectionElement.parentElement; - } - if (sectionElement) { - var sectionIndex = this.sections.indexOf(sectionElement.winControl); - if (sectionIndex > -1) { - this._currentIndexForSezo = sectionIndex; - } - } - - if (ev.target === this.element) { - var indexToFocus; - if (+this._sectionToFocus === this._sectionToFocus && this._sectionToFocus >= 0 && this._sectionToFocus < this.sections.length) { - indexToFocus = this._sectionToFocus; - this._sectionToFocus = null; - } else { - indexToFocus = this.sectionOnScreen; - } - - this._moveFocusIn(indexToFocus); - } - }, - _moveFocusIn: function hub_moveFocusIn(indexToFocus) { - if (indexToFocus >= 0) { - for (var i = indexToFocus; i < this.sections.length; i++) { - var section = this.sections.getAt(i); - - var focusAttempt = _ElementUtilities._trySetActive(section._headerTabStopElement, this._viewportElement); - - if (focusAttempt) { - return; - } - - if (_ElementUtilities._setActiveFirstFocusableElement(section.contentElement, this._viewportElement)) { - return; - } - } - - for (var i = indexToFocus - 1; i >= 0; i--) { - var section = this.sections.getAt(i); - - if (_ElementUtilities._setActiveFirstFocusableElement(section.contentElement, this._viewportElement)) { - return; - } - - var focusAttempt = _ElementUtilities._trySetActive(section._headerTabStopElement, this._viewportElement); - - if (focusAttempt) { - return; - } - } - } - }, - _keyDownHandler: function hub_keyDownHandler(ev) { - if (this._isInteractive(ev.target) || _ElementUtilities._hasCursorKeysBehaviors(ev.target)) { - return; - } - - var leftKey = this._rtl ? Key.rightArrow : Key.leftArrow; - var rightKey = this._rtl ? Key.leftArrow : Key.rightArrow; - - if (ev.keyCode === Key.upArrow || ev.keyCode === Key.downArrow || ev.keyCode === Key.leftArrow || ev.keyCode === Key.rightArrow || ev.keyCode === Key.pageUp || ev.keyCode === Key.pageDown) { - var headerTabStopElement = this._findHeaderTabStop(ev.target); - if (headerTabStopElement) { - var currentSection = this.sections.indexOf(headerTabStopElement.parentElement.parentElement.winControl); - var targetSectionIndex; - var useEnsureVisible = false; - // Page up/down go to the next/previous header and line it up with the app header. Up/Right/Down/Left - // move focus to the next/previous header and move it on screen (app header distance from either edge). - if (ev.keyCode === Key.pageDown || - (this.orientation === _UI.Orientation.horizontal && ev.keyCode === rightKey) || - (this.orientation === _UI.Orientation.vertical && ev.keyCode === Key.downArrow)) { - // Do not include hidden headers. - for (var i = currentSection + 1; i < this.sections.length; i++) { - if (this._tryFocus(i)) { - targetSectionIndex = i; - break; - } - } - } else if (ev.keyCode === Key.pageUp || - (this.orientation === _UI.Orientation.horizontal && ev.keyCode === leftKey) || - (this.orientation === _UI.Orientation.vertical && ev.keyCode === Key.upArrow)) { - // Do not include hidden headers. - for (var i = currentSection - 1; i >= 0; i--) { - if (this._tryFocus(i)) { - targetSectionIndex = i; - break; - } - } - } - if (ev.keyCode === Key.upArrow || ev.keyCode === Key.downArrow || ev.keyCode === Key.leftArrow || ev.keyCode === Key.rightArrow) { - useEnsureVisible = true; - } - - if (+targetSectionIndex === targetSectionIndex) { - if (useEnsureVisible) { - this._ensureVisible(targetSectionIndex, true); - } else { - this._scrollToSection(targetSectionIndex, true); - } - ev.preventDefault(); - } - } - } else if (ev.keyCode === Key.home || ev.keyCode === Key.end) { - // Home/End scroll to start/end and leave focus where it is. - this._measure(); - var maxScrollPos = Math.max(0, this._scrollLength - this._viewportSize); - this._scrollTo(ev.keyCode === Key.home ? 0 : maxScrollPos, true); - ev.preventDefault(); - } - }, - _tryFocus: function hub_tryFocus(index) { - var targetSection = this.sections.getAt(index); - - _ElementUtilities._setActive(targetSection._headerTabStopElement, this._viewportElement); - - return _Global.document.activeElement === targetSection._headerTabStopElement; - }, - /// - /// Gets a ZoomableView. This API supports the SemanticZoom infrastructure - /// and is not intended to be used directly from your code. - /// - /// - zoomableView: { - get: function zoomableView_get() { - if (!this._zoomableView) { - this._zoomableView = new ZoomableView(this); - } - - return this._zoomableView; - } - }, - _getPanAxis: function hub_getPanAxis() { - return this.orientation === _UI.Orientation.horizontal ? "horizontal" : "vertical"; - }, - _configureForZoom: function hub_configureForZoom() { - // Nothing to configure. - }, - _setCurrentItem: function hub_setCurrentItem(x, y) { - var offset; - if (this.orientation === _UI.Orientation.horizontal) { - offset = x; - } else { - offset = y; - } - - this._measure(); - offset = offset + this._scrollPosition; - this._currentIndexForSezo = this._sectionSizes.length - 1; - for (var i = 1; i < this._sectionSizes.length; i++) { - var sectionSize = this._sectionSizes[i]; - if (sectionSize.offset - sectionSize.marginStart > offset) { - this._currentIndexForSezo = i - 1; - break; - } - } - }, - _getCurrentItem: function hub_getCurrentItem() { - var itemPosition; - if (this._sectionSizes.length > 0) { - this._measure(); - var index = Math.max(0, Math.min(this._currentIndexForSezo, this._sectionSizes.length)); - var sectionSize = this._sectionSizes[index]; - if (this.orientation === _UI.Orientation.horizontal) { - itemPosition = { - left: Math.max(0, sectionSize.offset - sectionSize.marginStart - this._scrollPosition), - top: 0, - width: sectionSize.size, - height: this._viewportOppositeSize - }; - } else { - itemPosition = { - left: 0, - top: Math.max(0, sectionSize.offset - sectionSize.marginStart - this._scrollPosition), - width: this._viewportOppositeSize, - height: sectionSize.size, - }; - } - - var section = this.sections.getAt(index); - // BUGBUG: 53301 ListView and Hub should document what they expect to be returned from the - // getCurrentItem so that positionItem apis line up. ListView zoomed out expects an object with - // groupIndexHint, groupKey, or groupDescription. Hub expects an object with index. - return Promise.wrap({ item: { data: section, index: index, groupIndexHint: index }, position: itemPosition }); - } - }, - _beginZoom: function hub_beginZoom() { - // Hide scroll thumb. - this._viewportElement.style["-ms-overflow-style"] = "none"; - }, - _positionItem: function hub_positionItem(item, position) { - if (item.index >= 0 && item.index < this._sectionSizes.length) { - this._measure(); - var sectionSize = this._sectionSizes[item.index]; - - var offsetFromViewport; - if (this.orientation === _UI.Orientation.horizontal) { - offsetFromViewport = position.left; - } else { - offsetFromViewport = position.top; - } - - this._sectionToFocus = item.index; - - var targetScrollPosition = sectionSize.offset - offsetFromViewport; - // clamp section: - var targetScrollPosition = this._ensureVisibleMath(item.index, targetScrollPosition); - - this._scrollPosition = targetScrollPosition; - var newScrollPos = {}; - newScrollPos[this._names.scrollPos] = this._scrollPosition; - _ElementUtilities.setScrollPosition(this._viewportElement, newScrollPos); - } - }, - _endZoom: function hub_endZoom() { - // Show scroll thumb. - this._viewportElement.style["-ms-overflow-style"] = ""; - }, - _writeProfilerMark: function hub_writeProfilerMark(text) { - var message = "WinJS.UI.Hub:" + this._id + ":" + text; - _WriteProfilerMark(message); - _Log.log && _Log.log(message, null, "hubprofiler"); - }, - dispose: function hub_dispose() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - - _Global.removeEventListener('keydown', this._windowKeyDownHandlerBound); - _ElementUtilities._resizeNotifier.unsubscribe(this.element, this._resizeHandlerBound); - - this._updateEvents(this._sections); - - for (var i = 0; i < this.sections.length; i++) { - this.sections.getAt(i).dispose(); - } - } - }, { - /// - /// Specifies whether the Hub animation is an entrance animation or a transition animation. - /// - /// - AnimationType: { - /// - /// The animation plays when the Hub is first displayed. - /// - /// - entrance: "entrance", - /// - /// The animation plays when the Hub is changing its content. - /// - /// - contentTransition: "contentTransition", - /// - /// The animation plays when a section is inserted into the Hub. - /// - /// - insert: "insert", - /// - /// The animation plays when a section is removed into the Hub. - /// - /// - remove: "remove", - }, - /// - /// Gets the current loading state of the Hub. - /// - /// - LoadingState: { - /// - /// The Hub is loading sections. - /// - /// - loading: "loading", - /// - /// All sections are loaded and animations are complete. - /// - /// - complete: "complete" - }, - // Names of classes used by the Hub. - _ClassName: { - hub: "win-hub", - hubSurface: "win-hub-surface", - hubProgress: "win-hub-progress", - hubViewport: "win-hub-viewport", - hubVertical: "win-hub-vertical", - hubHorizontal: "win-hub-horizontal", - }, - // Names of events fired by the Hub. - _EventName: { - contentAnimating: eventNames.contentAnimating, - headerInvoked: eventNames.headerInvoked, - loadingStateChanged: eventNames.loadingStateChanged - }, - }); - - _Base.Class.mix(Hub, _Control.DOMEventMixin); - - var ZoomableView = _Base.Class.define(function ZoomableView_ctor(hub) { - this._hub = hub; - }, { - getPanAxis: function () { - return this._hub._getPanAxis(); - }, - configureForZoom: function (isZoomedOut, isCurrentView, triggerZoom, prefetchedPages) { - this._hub._configureForZoom(isZoomedOut, isCurrentView, triggerZoom, prefetchedPages); - }, - setCurrentItem: function (x, y) { - this._hub._setCurrentItem(x, y); - }, - getCurrentItem: function () { - return this._hub._getCurrentItem(); - }, - beginZoom: function () { - this._hub._beginZoom(); - }, - positionItem: function (item, position) { - return this._hub._positionItem(item, position); - }, - endZoom: function (isCurrentView) { - this._hub._endZoom(isCurrentView); - } - }); - - var strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get duplicateSection() { return "Hub duplicate sections: Each HubSection must be unique"; }, - get invalidContent() { return "Invalid content: Hub content must be made up of HubSections."; }, - get hubViewportAriaLabel() { return _Resources._getWinJSString("ui/hubViewportAriaLabel").value; } - }; - - return Hub; - }) - }); - -}); - -define('require-style!less/styles-lightdismissservice',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -define('WinJS/_LightDismissService',["require", "exports", './Application', './Core/_Base', './Core/_BaseUtils', './Utilities/_ElementUtilities', './Core/_Global', './Utilities/_KeyboardBehavior', './Core/_Log', './Core/_Resources'], function (require, exports, Application, _Base, _BaseUtils, _ElementUtilities, _Global, _KeyboardBehavior, _Log, _Resources) { - require(["require-style!less/styles-lightdismissservice"]); - "use strict"; - var baseZIndex = 1000; - var Strings = { - get closeOverlay() { - return _Resources._getWinJSString("ui/closeOverlay").value; - } - }; - exports._ClassNames = { - _clickEater: "win-clickeater" - }; - var EventNames = { - requestingFocusOnKeyboardInput: "requestingfocusonkeyboardinput" - }; - exports.LightDismissalReasons = { - tap: "tap", - lostFocus: "lostFocus", - escape: "escape", - hardwareBackButton: "hardwareBackButton", - windowResize: "windowResize", - windowBlur: "windowBlur" - }; - // Built-in implementations of ILightDismissable's onShouldLightDismiss. - exports.DismissalPolicies = { - light: function LightDismissalPolicies_light_onShouldLightDismiss(info) { - switch (info.reason) { - case exports.LightDismissalReasons.tap: - case exports.LightDismissalReasons.escape: - if (info.active) { - return true; - } - else { - info.stopPropagation(); - return false; - } - break; - case exports.LightDismissalReasons.hardwareBackButton: - if (info.active) { - info.preventDefault(); // prevent backwards navigation in the app - return true; - } - else { - info.stopPropagation(); - return false; - } - break; - case exports.LightDismissalReasons.lostFocus: - case exports.LightDismissalReasons.windowResize: - case exports.LightDismissalReasons.windowBlur: - return true; - } - }, - modal: function LightDismissalPolicies_modal_onShouldLightDismiss(info) { - // Light dismiss cues should not be seen by dismissables behind the modal - info.stopPropagation(); - switch (info.reason) { - case exports.LightDismissalReasons.tap: - case exports.LightDismissalReasons.lostFocus: - case exports.LightDismissalReasons.windowResize: - case exports.LightDismissalReasons.windowBlur: - return false; - break; - case exports.LightDismissalReasons.escape: - return info.active; - break; - case exports.LightDismissalReasons.hardwareBackButton: - info.preventDefault(); // prevent backwards navigation in the app - return info.active; - break; - } - }, - sticky: function LightDismissalPolicies_sticky_onShouldLightDismiss(info) { - info.stopPropagation(); - return false; - } - }; - var KeyboardInfoType = { - keyDown: "keyDown", - keyUp: "keyUp", - keyPress: "keyPress" - }; - var AbstractDismissableElement = (function () { - function AbstractDismissableElement(args) { - this.element = args.element; - this.element.tabIndex = args.tabIndex; - this.onLightDismiss = args.onLightDismiss; - // Allow the caller to override the default implementations of our ILightDismissable methods. - if (args.onTakeFocus) { - this.onTakeFocus = args.onTakeFocus; - } - if (args.onShouldLightDismiss) { - this.onShouldLightDismiss = args.onShouldLightDismiss; - } - this._ldeOnKeyDownBound = this._ldeOnKeyDown.bind(this); - this._ldeOnKeyUpBound = this._ldeOnKeyUp.bind(this); - this._ldeOnKeyPressBound = this._ldeOnKeyPress.bind(this); - } - AbstractDismissableElement.prototype.restoreFocus = function () { - var activeElement = _Global.document.activeElement; - if (activeElement && this.containsElement(activeElement)) { - this._ldeCurrentFocus = activeElement; - return true; - } - else { - // If the last input type was keyboard, use focus() so a keyboard focus visual is drawn. - // Otherwise, use setActive() so no focus visual is drawn. - var useSetActive = !_KeyboardBehavior._keyboardSeenLast; - return this._ldeCurrentFocus && this.containsElement(this._ldeCurrentFocus) && _ElementUtilities._tryFocusOnAnyElement(this._ldeCurrentFocus, useSetActive); - } - }; - AbstractDismissableElement.prototype._ldeOnKeyDown = function (eventObject) { - this._ldeService.keyDown(this, eventObject); - }; - AbstractDismissableElement.prototype._ldeOnKeyUp = function (eventObject) { - this._ldeService.keyUp(this, eventObject); - }; - AbstractDismissableElement.prototype._ldeOnKeyPress = function (eventObject) { - this._ldeService.keyPress(this, eventObject); - }; - // ILightDismissable - // - AbstractDismissableElement.prototype.setZIndex = function (zIndex) { - this.element.style.zIndex = zIndex; - }; - AbstractDismissableElement.prototype.getZIndexCount = function () { - return 1; - }; - AbstractDismissableElement.prototype.containsElement = function (element) { - return this.element.contains(element); - }; - AbstractDismissableElement.prototype.onTakeFocus = function (useSetActive) { - this.restoreFocus() || _ElementUtilities._focusFirstFocusableElement(this.element, useSetActive) || _ElementUtilities._tryFocusOnAnyElement(this.element, useSetActive); - }; - AbstractDismissableElement.prototype.onFocus = function (element) { - this._ldeCurrentFocus = element; - }; - AbstractDismissableElement.prototype.onShow = function (service) { - this._ldeService = service; - this.element.addEventListener("keydown", this._ldeOnKeyDownBound); - this.element.addEventListener("keyup", this._ldeOnKeyUpBound); - this.element.addEventListener("keypress", this._ldeOnKeyPressBound); - }; - AbstractDismissableElement.prototype.onHide = function () { - this._ldeCurrentFocus = null; - this._ldeService = null; - this.element.removeEventListener("keydown", this._ldeOnKeyDownBound); - this.element.removeEventListener("keyup", this._ldeOnKeyUpBound); - this.element.removeEventListener("keypress", this._ldeOnKeyPressBound); - }; - // Concrete subclasses are expected to implement these. - AbstractDismissableElement.prototype.onKeyInStack = function (info) { - }; - AbstractDismissableElement.prototype.onShouldLightDismiss = function (info) { - return false; - }; - // Consumers of concrete subclasses of AbstractDismissableElement are expected to - // provide these as parameters to the constructor. - AbstractDismissableElement.prototype.onLightDismiss = function (info) { - }; - return AbstractDismissableElement; - })(); - var LightDismissableElement = (function (_super) { - __extends(LightDismissableElement, _super); - function LightDismissableElement() { - _super.apply(this, arguments); - } - LightDismissableElement.prototype.onKeyInStack = function (info) { - }; - LightDismissableElement.prototype.onShouldLightDismiss = function (info) { - return exports.DismissalPolicies.light(info); - }; - return LightDismissableElement; - })(AbstractDismissableElement); - exports.LightDismissableElement = LightDismissableElement; - var ModalElement = (function (_super) { - __extends(ModalElement, _super); - function ModalElement() { - _super.apply(this, arguments); - } - ModalElement.prototype.onKeyInStack = function (info) { - // stopPropagation so that none of the app's other event handlers will see the event. - // Don't preventDefault so that the browser's hotkeys will still work. - info.stopPropagation(); - }; - ModalElement.prototype.onShouldLightDismiss = function (info) { - return exports.DismissalPolicies.modal(info); - }; - return ModalElement; - })(AbstractDismissableElement); - exports.ModalElement = ModalElement; - // An implementation of ILightDismissable that represents the HTML body element. It can never be dismissed. The - // service should instantiate one of these to act as the bottommost light dismissable at all times (it isn't expected - // for anybody else to instantiate one). It takes care of restoring focus when the last dismissable is dismissed. - var LightDismissableBody = (function () { - function LightDismissableBody() { - } - LightDismissableBody.prototype.setZIndex = function (zIndex) { - }; - LightDismissableBody.prototype.getZIndexCount = function () { - return 1; - }; - LightDismissableBody.prototype.containsElement = function (element) { - return _Global.document.body.contains(element); - }; - LightDismissableBody.prototype.onTakeFocus = function (useSetActive) { - this.currentFocus && this.containsElement(this.currentFocus) && _ElementUtilities._tryFocusOnAnyElement(this.currentFocus, useSetActive); - }; - LightDismissableBody.prototype.onFocus = function (element) { - this.currentFocus = element; - }; - LightDismissableBody.prototype.onShow = function (service) { - }; - LightDismissableBody.prototype.onHide = function () { - this.currentFocus = null; - }; - LightDismissableBody.prototype.onKeyInStack = function (info) { - }; - LightDismissableBody.prototype.onShouldLightDismiss = function (info) { - return false; - }; - LightDismissableBody.prototype.onLightDismiss = function (info) { - }; - return LightDismissableBody; - })(); - ; - var LightDismissService = (function () { - function LightDismissService() { - this._debug = false; // Disables dismiss due to window blur. Useful during debugging. - this._clients = []; - this._notifying = false; - this._bodyClient = new LightDismissableBody(); - // State private to _updateDom. No other method should make use of it. - this._updateDom_rendered = { - serviceActive: false - }; - this._clickEaterEl = this._createClickEater(); - this._onBeforeRequestingFocusOnKeyboardInputBound = this._onBeforeRequestingFocusOnKeyboardInput.bind(this); - this._onFocusInBound = this._onFocusIn.bind(this); - this._onKeyDownBound = this._onKeyDown.bind(this); - this._onWindowResizeBound = this._onWindowResize.bind(this); - this._onClickEaterPointerUpBound = this._onClickEaterPointerUp.bind(this); - this._onClickEaterPointerCancelBound = this._onClickEaterPointerCancel.bind(this); - // Register for infrequent events. - Application.addEventListener("backclick", this._onBackClick.bind(this)); - // Focus handlers generally use _ElementUtilities._addEventListener with focusout/focusin. This - // uses the browser's blur event directly beacuse _addEventListener doesn't support focusout/focusin - // on window. - _Global.window.addEventListener("blur", this._onWindowBlur.bind(this)); - this.shown(this._bodyClient); - } - // Dismissables should call this as soon as they are ready to be shown. More specifically, they should call this: - // - After they are in the DOM and ready to receive focus (e.g. style.display cannot = "none") - // - Before their entrance animation is played - LightDismissService.prototype.shown = function (client) { - var index = this._clients.indexOf(client); - if (index === -1) { - this._clients.push(client); - client.onShow(this); - this._updateDom(); - } - }; - // Dismissables should call this when they are done being dismissed (i.e. after their exit animation has finished) - LightDismissService.prototype.hidden = function (client) { - var index = this._clients.indexOf(client); - if (index !== -1) { - this._clients.splice(index, 1); - client.setZIndex(""); - client.onHide(); - this._updateDom(); - } - }; - // Dismissables should call this when their state has changed such that it'll affect the behavior of some method - // in its ILightDismissable interface. For example, if the dismissable was altered such that getZIndexCount will - // now return 2 instead of 1, that dismissable should call *updated* so the LightDismissService can find out about - // this change. - LightDismissService.prototype.updated = function (client) { - this._updateDom(); - }; - LightDismissService.prototype.keyDown = function (client, eventObject) { - if (eventObject.keyCode === _ElementUtilities.Key.escape) { - this._escapePressed(eventObject); - } - else { - this._dispatchKeyboardEvent(client, KeyboardInfoType.keyDown, eventObject); - } - }; - LightDismissService.prototype.keyUp = function (client, eventObject) { - this._dispatchKeyboardEvent(client, KeyboardInfoType.keyUp, eventObject); - }; - LightDismissService.prototype.keyPress = function (client, eventObject) { - this._dispatchKeyboardEvent(client, KeyboardInfoType.keyPress, eventObject); - }; - LightDismissService.prototype.isShown = function (client) { - return this._clients.indexOf(client) !== -1; - }; - LightDismissService.prototype.isTopmost = function (client) { - return client === this._clients[this._clients.length - 1]; - }; - // Disables dismiss due to window blur. Useful during debugging. - LightDismissService.prototype._setDebug = function (debug) { - this._debug = debug; - }; - LightDismissService.prototype._updateDom = function (options) { - options = options || {}; - var activeDismissableNeedsFocus = !!options.activeDismissableNeedsFocus; - var rendered = this._updateDom_rendered; - if (this._notifying) { - return; - } - var serviceActive = this._clients.length > 1; - if (serviceActive !== rendered.serviceActive) { - // Unregister/register for events that occur frequently. - if (serviceActive) { - Application.addEventListener("beforerequestingfocusonkeyboardinput", this._onBeforeRequestingFocusOnKeyboardInputBound); - _ElementUtilities._addEventListener(_Global.document.documentElement, "focusin", this._onFocusInBound); - _Global.document.documentElement.addEventListener("keydown", this._onKeyDownBound); - _Global.window.addEventListener("resize", this._onWindowResizeBound); - this._bodyClient.currentFocus = _Global.document.activeElement; - _Global.document.body.appendChild(this._clickEaterEl); - } - else { - Application.removeEventListener("beforerequestingfocusonkeyboardinput", this._onBeforeRequestingFocusOnKeyboardInputBound); - _ElementUtilities._removeEventListener(_Global.document.documentElement, "focusin", this._onFocusInBound); - _Global.document.documentElement.removeEventListener("keydown", this._onKeyDownBound); - _Global.window.removeEventListener("resize", this._onWindowResizeBound); - var parent = this._clickEaterEl.parentNode; - parent && parent.removeChild(this._clickEaterEl); - } - rendered.serviceActive = serviceActive; - } - var zIndexGap = 0; - var lastUsedZIndex = baseZIndex + 1; - this._clients.forEach(function (c, i) { - var currentZIndex = lastUsedZIndex + zIndexGap; - c.setZIndex("" + currentZIndex); - lastUsedZIndex = currentZIndex; - // count + 1 so that there's an unused zIndex between each pair of - // dismissables that can be used by the click eater. - zIndexGap = c.getZIndexCount() + 1; - }); - if (serviceActive) { - this._clickEaterEl.style.zIndex = "" + (lastUsedZIndex - 1); - } - var activeDismissable = this._clients.length > 0 ? this._clients[this._clients.length - 1] : null; - if (this._activeDismissable !== activeDismissable) { - this._activeDismissable = activeDismissable; - activeDismissableNeedsFocus = true; - } - if (activeDismissableNeedsFocus) { - // If the last input type was keyboard, use focus() so a keyboard focus visual is drawn. - // Otherwise, use setActive() so no focus visual is drawn. - var useSetActive = !_KeyboardBehavior._keyboardSeenLast; - this._activeDismissable && this._activeDismissable.onTakeFocus(useSetActive); - } - }; - LightDismissService.prototype._dispatchKeyboardEvent = function (client, keyboardInfoType, eventObject) { - var index = this._clients.indexOf(client); - if (index !== -1) { - var info = { - type: keyboardInfoType, - keyCode: eventObject.keyCode, - propagationStopped: false, - stopPropagation: function () { - this.propagationStopped = true; - eventObject.stopPropagation(); - } - }; - var clients = this._clients.slice(0, index + 1); - for (var i = clients.length - 1; i >= 0 && !info.propagationStopped; i--) { - clients[i].onKeyInStack(info); - } - } - }; - LightDismissService.prototype._dispatchLightDismiss = function (reason, clients, options) { - if (this._notifying) { - _Log.log && _Log.log('_LightDismissService ignored dismiss trigger to avoid re-entrancy: "' + reason + '"', "winjs _LightDismissService", "warning"); - return; - } - clients = clients || this._clients.slice(0); - if (clients.length === 0) { - return; - } - this._notifying = true; - var lightDismissInfo = { - // Which of the LightDismissalReasons caused this event to fire? - reason: reason, - // Is this dismissable currently the active dismissable? - active: false, - _stop: false, - stopPropagation: function () { - this._stop = true; - }, - _doDefault: true, - preventDefault: function () { - this._doDefault = false; - } - }; - for (var i = clients.length - 1; i >= 0 && !lightDismissInfo._stop; i--) { - lightDismissInfo.active = this._activeDismissable === clients[i]; - if (clients[i].onShouldLightDismiss(lightDismissInfo)) { - clients[i].onLightDismiss(lightDismissInfo); - } - } - this._notifying = false; - this._updateDom(options); - return lightDismissInfo._doDefault; - }; - LightDismissService.prototype._onBeforeRequestingFocusOnKeyboardInput = function (eventObject) { - // Suppress the requestingFocusOnKeyboardInput event. - return true; - }; - // - // Light dismiss triggers - // - // Called by tests. - LightDismissService.prototype._clickEaterTapped = function () { - this._dispatchLightDismiss(exports.LightDismissalReasons.tap); - }; - LightDismissService.prototype._onFocusIn = function (eventObject) { - var target = eventObject.target; - for (var i = this._clients.length - 1; i >= 0; i--) { - if (this._clients[i].containsElement(target)) { - break; - } - } - if (i !== -1) { - this._clients[i].onFocus(target); - } - if (i + 1 < this._clients.length) { - this._dispatchLightDismiss(exports.LightDismissalReasons.lostFocus, this._clients.slice(i + 1), { - activeDismissableNeedsFocus: true - }); - } - }; - LightDismissService.prototype._onKeyDown = function (eventObject) { - if (eventObject.keyCode === _ElementUtilities.Key.escape) { - this._escapePressed(eventObject); - } - }; - LightDismissService.prototype._escapePressed = function (eventObject) { - eventObject.preventDefault(); - eventObject.stopPropagation(); - this._dispatchLightDismiss(exports.LightDismissalReasons.escape); - }; - // Called by tests. - LightDismissService.prototype._onBackClick = function (eventObject) { - var doDefault = this._dispatchLightDismiss(exports.LightDismissalReasons.hardwareBackButton); - return !doDefault; // Returns whether or not the event was handled. - }; - LightDismissService.prototype._onWindowResize = function (eventObject) { - this._dispatchLightDismiss(exports.LightDismissalReasons.windowResize); - }; - LightDismissService.prototype._onWindowBlur = function (eventObject) { - if (this._debug) { - return; - } - // Want to trigger a light dismiss on window blur. - // We get blur if we click off the window, including into an iframe within our window. - // Both blurs call this function, but fortunately document.hasFocus is true if either - // the document window or our iframe window has focus. - if (!_Global.document.hasFocus()) { - // The document doesn't have focus, so they clicked off the app, so light dismiss. - this._dispatchLightDismiss(exports.LightDismissalReasons.windowBlur); - } - else { - // We were trying to unfocus the window, but document still has focus, - // so make sure the iframe that took the focus will check for blur next time. - var active = _Global.document.activeElement; - if (active && active.tagName === "IFRAME" && !active["msLightDismissBlur"]) { - // - This will go away when the IFRAME goes away, and we only create one. - // - This only works in IE because other browsers don't fire focus events on iframe elements. - // - Can't use _ElementUtilities._addEventListener's focusout because it doesn't fire when an - // iframe loses focus due to changing windows. - active.addEventListener("blur", this._onWindowBlur.bind(this), false); - active["msLightDismissBlur"] = true; - } - } - }; - LightDismissService.prototype._createClickEater = function () { - var clickEater = _Global.document.createElement("section"); - clickEater.className = exports._ClassNames._clickEater; - _ElementUtilities._addEventListener(clickEater, "pointerdown", this._onClickEaterPointerDown.bind(this), true); - clickEater.addEventListener("click", this._onClickEaterClick.bind(this), true); - // Tell Aria that it's clickable - clickEater.setAttribute("role", "menuitem"); - clickEater.setAttribute("aria-label", Strings.closeOverlay); - // Prevent CED from removing any current selection - clickEater.setAttribute("unselectable", "on"); - return clickEater; - }; - LightDismissService.prototype._onClickEaterPointerDown = function (eventObject) { - eventObject.stopPropagation(); - eventObject.preventDefault(); - this._clickEaterPointerId = eventObject.pointerId; - if (!this._registeredClickEaterCleanUp) { - _ElementUtilities._addEventListener(_Global.window, "pointerup", this._onClickEaterPointerUpBound); - _ElementUtilities._addEventListener(_Global.window, "pointercancel", this._onClickEaterPointerCancelBound); - this._registeredClickEaterCleanUp = true; - } - }; - LightDismissService.prototype._onClickEaterPointerUp = function (eventObject) { - var _this = this; - eventObject.stopPropagation(); - eventObject.preventDefault(); - if (eventObject.pointerId === this._clickEaterPointerId) { - this._resetClickEaterPointerState(); - var element = _Global.document.elementFromPoint(eventObject.clientX, eventObject.clientY); - if (element === this._clickEaterEl) { - this._skipClickEaterClick = true; - _BaseUtils._yieldForEvents(function () { - _this._skipClickEaterClick = false; - }); - this._clickEaterTapped(); - } - } - }; - LightDismissService.prototype._onClickEaterClick = function (eventObject) { - eventObject.stopPropagation(); - eventObject.preventDefault(); - if (!this._skipClickEaterClick) { - // Handle the UIA invoke action on the click eater. this._skipClickEaterClick is false which tells - // us that we received a click event without an associated PointerUp event. This means that the click - // event was triggered thru UIA rather than thru the GUI. - this._clickEaterTapped(); - } - }; - LightDismissService.prototype._onClickEaterPointerCancel = function (eventObject) { - if (eventObject.pointerId === this._clickEaterPointerId) { - this._resetClickEaterPointerState(); - } - }; - LightDismissService.prototype._resetClickEaterPointerState = function () { - if (this._registeredClickEaterCleanUp) { - _ElementUtilities._removeEventListener(_Global.window, "pointerup", this._onClickEaterPointerUpBound); - _ElementUtilities._removeEventListener(_Global.window, "pointercancel", this._onClickEaterPointerCancelBound); - } - this._clickEaterPointerId = null; - this._registeredClickEaterCleanUp = false; - }; - return LightDismissService; - })(); - var service = new LightDismissService(); - exports.shown = service.shown.bind(service); - exports.hidden = service.hidden.bind(service); - exports.updated = service.updated.bind(service); - exports.isShown = service.isShown.bind(service); - exports.isTopmost = service.isTopmost.bind(service); - exports.keyDown = service.keyDown.bind(service); - exports.keyUp = service.keyUp.bind(service); - exports.keyPress = service.keyPress.bind(service); - exports._clickEaterTapped = service._clickEaterTapped.bind(service); - exports._onBackClick = service._onBackClick.bind(service); - exports._setDebug = service._setDebug.bind(service); - _Base.Namespace.define("WinJS.UI._LightDismissService", { - shown: exports.shown, - hidden: exports.hidden, - updated: exports.updated, - isShown: exports.isShown, - isTopmost: exports.isTopmost, - keyDown: exports.keyDown, - keyUp: exports.keyUp, - keyPress: exports.keyPress, - _clickEaterTapped: exports._clickEaterTapped, - _onBackClick: exports._onBackClick, - _setDebug: exports._setDebug, - LightDismissableElement: LightDismissableElement, - DismissalPolicies: exports.DismissalPolicies, - LightDismissalReasons: exports.LightDismissalReasons, - _ClassNames: exports._ClassNames, - _service: service - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/_LegacyAppBar/_Constants',[ - 'exports', - '../../Core/_Base', -], function appBarConstantsInit(exports, _Base) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, null, { - // AppBar class names. - appBarClass: "win-navbar", - firstDivClass: "win-firstdiv", - finalDivClass: "win-finaldiv", - invokeButtonClass: "win-navbar-invokebutton", - ellipsisClass: "win-navbar-ellipsis", - primaryCommandsClass: "win-primarygroup", - secondaryCommandsClass: "win-secondarygroup", - commandLayoutClass: "win-commandlayout", - menuLayoutClass: "win-menulayout", - topClass: "win-top", - bottomClass: "win-bottom", - showingClass : "win-navbar-opening", - shownClass : "win-navbar-opened", - hidingClass : "win-navbar-closing", - hiddenClass: "win-navbar-closed", - compactClass: "win-navbar-compact", - minimalClass: "win-navbar-minimal", - menuContainerClass: "win-navbar-menu", - - // Constants for AppBar placement - appBarPlacementTop: "top", - appBarPlacementBottom: "bottom", - - // Constants for AppBar layouts - appBarLayoutCustom: "custom", - appBarLayoutCommands: "commands", - appBarLayoutMenu: "menu", - - // Constant for AppBar invokebutton width - appBarInvokeButtonWidth: 32, - - // Constants for Commands - typeSeparator: "separator", - typeContent: "content", - typeButton: "button", - typeToggle: "toggle", - typeFlyout: "flyout", - appBarCommandClass: "win-command", - appBarCommandGlobalClass: "win-global", - appBarCommandSelectionClass: "win-selection", - sectionSelection: "selection", /* deprecated, use sectionSecondary */ - sectionGlobal: "global", /* deprecated, use sectionPrimary */ - sectionPrimary: "primary", - sectionSecondary: "secondary", - - // Constants for Menus - menuCommandClass: "win-command", - menuCommandButtonClass: "win-command-button", - menuCommandToggleClass: "win-command-toggle", - menuCommandFlyoutClass: "win-command-flyout", - menuCommandFlyoutActivatedClass: "win-command-flyout-activated", - menuCommandSeparatorClass: "win-command-separator", - _menuCommandInvokedEvent: "_invoked", // Private event - menuClass: "win-menu", - menuContainsToggleCommandClass: "win-menu-containstogglecommand", - menuContainsFlyoutCommandClass: "win-menu-containsflyoutcommand", - menuMouseSpacingClass: "win-menu-mousespacing", - menuTouchSpacingClass: "win-menu-touchspacing", - menuCommandHoverDelay: 400, - - // Other class names - overlayClass: "win-overlay", - flyoutClass: "win-flyout", - flyoutLightClass: "win-ui-light", - settingsFlyoutClass: "win-settingsflyout", - scrollsClass: "win-scrolls", - pinToRightEdge: -1, - pinToBottomEdge: -1, - - // Constants for AppBarCommand full-size widths. - separatorWidth: 34, - buttonWidth: 68, - - narrowClass: "win-narrow", - wideClass: "win-wide", - _visualViewportClass: "win-visualviewport-space", - - // Event names - commandPropertyMutated: "_commandpropertymutated", - commandVisibilityChanged: "commandvisibilitychanged", - }); -}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Utilities/_KeyboardInfo',["require", "exports", '../Core/_BaseCoreUtils', '../Core/_Global', '../Core/_WinRT'], function (require, exports, _BaseCoreUtils, _Global, _WinRT) { - "use strict"; - var _Constants = { - visualViewportClass: "win-visualviewport-space", - scrollTimeout: 150, - }; - // This private module provides accurate metrics for the Visual Viewport and WWA's IHM offsets in Win10 WWA - // where "-ms-device-fixed" CSS positioning is supported. WinJS controls will also use this module for - // positoning themselves relative to the viewport in a web browser outside of WWA. Their preference is still - // to rely on "-ms-device-fixed" positioning, but currently fallback to "fixed" positioning in enviornments where - // "-ms-device-fixed" is not supported. - exports._KeyboardInfo; - // WWA Soft Keyboard offsets - exports._KeyboardInfo = { - // Determine if the keyboard is visible or not. - get _visible() { - try { - return (_WinRT.Windows.UI.ViewManagement.InputPane && _WinRT.Windows.UI.ViewManagement.InputPane.getForCurrentView().occludedRect.height > 0); - } - catch (e) { - return false; - } - }, - // See if we have to reserve extra space for the IHM - get _extraOccluded() { - var occluded = 0; - // Controls using -ms-device-fixed positioning only need to reposition themselves to remain visible - // If the IHM has not resized the viewport. - if (!exports._KeyboardInfo._isResized && _WinRT.Windows.UI.ViewManagement.InputPane) { - occluded = _WinRT.Windows.UI.ViewManagement.InputPane.getForCurrentView().occludedRect.height; - } - return occluded; - }, - // See if the view has been resized to fit a keyboard - get _isResized() { - // Compare ratios. Very different includes IHM space. - var heightRatio = _Global.document.documentElement.clientHeight / _Global.innerHeight, widthRatio = _Global.document.documentElement.clientWidth / _Global.innerWidth; - // If they're nearly identical, then the view hasn't been resized for the IHM - // Only check one bound because we know the IHM will make it shorter, not skinnier. - return (widthRatio / heightRatio < 0.99); - }, - // Get the bottom of the visible area, relative to the top edge of the visible area. - get _visibleDocBottom() { - return exports._KeyboardInfo._visibleDocTop + exports._KeyboardInfo._visibleDocHeight; - }, - // Get the height of the visible area, e.g. the height of the visual viewport minus any IHM occlusion. - get _visibleDocHeight() { - return exports._KeyboardInfo._visualViewportHeight - exports._KeyboardInfo._extraOccluded; - }, - // Get the top offset of our visible area, aka the top of the visual viewport. - // This is always 0 when elements use -ms-device-fixed positioning. - get _visibleDocTop() { - return 0; - }, - // Get the offset for, and relative to, the bottom edge of the visual viewport plus any IHM occlusion. - get _visibleDocBottomOffset() { - // For -ms-device-fixed positioned elements, the bottom is just 0 when there's no IHM. - // When the IHM appears, the text input that invoked it may be in a position on the page that is occluded by the IHM. - // In that instance, the default browser behavior is to resize the visual viewport and scroll the input back into view. - // However, if the viewport resize is prevented by an IHM event listener, the keyboard will still occlude - // -ms-device-fixed elements, so we adjust the bottom offset of the appbar by the height of the occluded rect of the IHM. - return exports._KeyboardInfo._extraOccluded; - }, - // Get the visual viewport height. window.innerHeight doesn't return floating point values which are present with high DPI. - get _visualViewportHeight() { - var boundingRect = exports._KeyboardInfo._visualViewportSpace; - return boundingRect.height; - }, - // Get the visual viewport width. window.innerWidth doesn't return floating point values which are present with high DPI. - get _visualViewportWidth() { - var boundingRect = exports._KeyboardInfo._visualViewportSpace; - return boundingRect.width; - }, - // The visual viewport space element is hidden given -ms-device-fixed positioning and used to calculate - // the 4 edges of the visual viewport with floating point precision. - get _visualViewportSpace() { - var visualViewportSpace = _Global.document.body.querySelector("." + _Constants.visualViewportClass); - if (!visualViewportSpace) { - visualViewportSpace = _Global.document.createElement("DIV"); - visualViewportSpace.className = _Constants.visualViewportClass; - _Global.document.body.appendChild(visualViewportSpace); - } - return visualViewportSpace.getBoundingClientRect(); - }, - // Get total length of the IHM showPanel animation - get _animationShowLength() { - if (_BaseCoreUtils.hasWinRT) { - if (_WinRT.Windows.UI.Core.AnimationMetrics) { - // Desktop exposes the AnimationMetrics API that allows us to look up the relevant IHM animation metrics. - var a = _WinRT.Windows.UI.Core.AnimationMetrics, animationDescription = new a.AnimationDescription(a.AnimationEffect.showPanel, a.AnimationEffectTarget.primary); - var animations = animationDescription.animations; - var max = 0; - for (var i = 0; i < animations.size; i++) { - var animation = animations[i]; - max = Math.max(max, animation.delay + animation.duration); - } - return max; - } - else { - // Phone platform does not yet expose the Animation Metrics API. - // Hard code the correct values for the time being. - // https://github.com/winjs/winjs/issues/1060 - var animationDuration = 300; - var animationDelay = 50; - return animationDelay + animationDuration; - } - } - else { - return 0; - } - }, - // Padding for IHM timer to allow for first scroll event. Tpyically used in conjunction with the - // _animationShowLength to determine the length of time in which a showing IHM would have triggered - // a window resize to occur. - get _scrollTimeout() { - return _Constants.scrollTimeout; - }, - // _layoutViewportCoords is used with elements that use position:fixed instead of position:-ms-device-fixed - get _layoutViewportCoords() { - var topOffset = _Global.window.pageYOffset - _Global.document.documentElement.scrollTop; - var bottomOffset = _Global.document.documentElement.clientHeight - (topOffset + this._visibleDocHeight); - return { - visibleDocTop: topOffset, - visibleDocBottom: bottomOffset - }; - } - }; -}); - - -define('require-style!less/styles-overlay',[],function(){}); - -define('require-style!less/colors-overlay',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// animatable,appbar,appbars,divs,Flyout,Flyouts,iframe,Statics,unfocus,unselectable -define('WinJS/Controls/Flyout/_Overlay',[ - 'exports', - '../../Core/_Global', - '../../Core/_WinRT', - '../../Core/_Base', - '../../Core/_BaseUtils', - '../../Core/_ErrorFromName', - '../../Core/_Events', - '../../Core/_Resources', - '../../Core/_WriteProfilerMark', - '../../_Accents', - '../../Animations', - '../../Application', - '../../ControlProcessor', - '../../Promise', - '../../Scheduler', - '../../Utilities/_Control', - '../../Utilities/_ElementUtilities', - '../../Utilities/_KeyboardInfo', - '../_LegacyAppBar/_Constants', - 'require-style!less/styles-overlay', - 'require-style!less/colors-overlay' -], function overlayInit(exports, _Global, _WinRT, _Base, _BaseUtils, _ErrorFromName, _Events, _Resources, _WriteProfilerMark, _Accents, Animations, Application, ControlProcessor, Promise, Scheduler, _Control, _ElementUtilities, _KeyboardInfo, _Constants) { - "use strict"; - - _Accents.createAccentRule( - "button[aria-checked=true].win-command:before,\ - .win-menu-containsflyoutcommand button.win-command-flyout-activated:before", [ - { name: "background-color", value: _Accents.ColorTypes.accent }, - { name: "border-color", value: _Accents.ColorTypes.accent }, - ]); - - _Accents.createAccentRule(".win-flyout, .win-settingsflyout", [{ name: "border-color", value: _Accents.ColorTypes.accent }]); - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - _Overlay: _Base.Namespace._lazy(function () { - - // Helper for Global Event listeners. Invokes the specified callback member function on each _Overlay in the DOM. - function _allOverlaysCallback(event, nameOfFunctionCall, stopImmediatePropagationWhenHandled) { - var elements = _Global.document.querySelectorAll("." + _Constants.overlayClass); - if (elements) { - var len = elements.length; - for (var i = 0; i < len; i++) { - var element = elements[i]; - var overlay = element.winControl; - if (!overlay._disposed) { - if (overlay) { - var handled = overlay[nameOfFunctionCall](event); - if (stopImmediatePropagationWhenHandled && handled) { - // The caller has indicated we should exit as soon as the event is handled. - return handled; - } - } - } - } - } - } - - // _Overlay Global Events Listener Class. We hang a singleton instance of this class off of a static _Overlay property. - var _GlobalListener = _Base.Class.define(function _GlobalListener_ctor() { - this._currentState = _GlobalListener.states.off; - - this._inputPaneShowing = this._inputPaneShowing.bind(this); - this._inputPaneHiding = this._inputPaneHiding.bind(this); - this._documentScroll = this._documentScroll.bind(this); - this._windowResized = this._windowResized.bind(this); - }, { - initialize: function _GlobalListener_initialize() { - this._toggleListeners(_GlobalListener.states.on); - }, - // Expose this for unit tests. - reset: function _GlobalListener_reset() { - this._toggleListeners(_GlobalListener.states.off); - this._toggleListeners(_GlobalListener.states.on); - }, - _inputPaneShowing: function _GlobalListener_inputePaneShowing(event) { - _WriteProfilerMark(_GlobalListener.profilerString + "_showingKeyboard,StartTM"); - _allOverlaysCallback(event, "_showingKeyboard"); - _WriteProfilerMark(_GlobalListener.profilerString + "_showingKeyboard,StopTM"); - }, - _inputPaneHiding: function _GlobalListener_inputPaneHiding(event) { - _WriteProfilerMark(_GlobalListener.profilerString + "_hidingKeyboard,StartTM"); - _allOverlaysCallback(event, "_hidingKeyboard"); - _WriteProfilerMark(_GlobalListener.profilerString + "_hidingKeyboard,StopTM"); - }, - _documentScroll: function _GlobalListener_documentScroll(event) { - _WriteProfilerMark(_GlobalListener.profilerString + "_checkScrollPosition,StartTM"); - _allOverlaysCallback(event, "_checkScrollPosition"); - _WriteProfilerMark(_GlobalListener.profilerString + "_checkScrollPosition,StopTM"); - }, - _windowResized: function _GlobalListener_windowResized(event) { - _WriteProfilerMark(_GlobalListener.profilerString + "_baseResize,StartTM"); - _allOverlaysCallback(event, "_baseResize"); - _WriteProfilerMark(_GlobalListener.profilerString + "_baseResize,StopTM"); - }, - _toggleListeners: function _GlobalListener_toggleListeners(newState) { - // Add/Remove global event listeners for all _Overlays - var listenerOperation; - if (this._currentState !== newState) { - if (newState === _GlobalListener.states.on) { - listenerOperation = "addEventListener"; - } else if (newState === _GlobalListener.states.off) { - listenerOperation = "removeEventListener"; - } - - if (_WinRT.Windows.UI.ViewManagement.InputPane) { - // React to Soft Keyboard events - var inputPane = _WinRT.Windows.UI.ViewManagement.InputPane.getForCurrentView(); - inputPane[listenerOperation]("showing", this._inputPaneShowing, false); - inputPane[listenerOperation]("hiding", this._inputPaneHiding, false); - - _Global.document[listenerOperation]("scroll", this._documentScroll, false); - } - - // Window resize event - _Global.addEventListener("resize", this._windowResized, false); - - this._currentState = newState; - } - }, - }, { - // Statics - profilerString: { - get: function () { - return "WinJS.UI._Overlay Global Listener:"; - } - }, - states: { - get: function () { - return { - off: 0, - on: 1, - }; - }, - }, - }); - - // Helper to get DOM elements from input single object or array or IDs/toolkit/dom elements - function _resolveElements(elements) { - // No input is just an empty array - if (!elements) { - return []; - } - - // Make sure it's in array form. - if (typeof elements === "string" || !elements || !elements.length) { - elements = [elements]; - } - - // Make sure we have a DOM element for each one, (could be string id name or toolkit object) - var i, - realElements = []; - for (i = 0; i < elements.length; i++) { - if (elements[i]) { - if (typeof elements[i] === "string") { - var element = _Global.document.getElementById(elements[i]); - if (element) { - realElements.push(element); - } - } else if (elements[i].element) { - realElements.push(elements[i].element); - } else { - realElements.push(elements[i]); - } - } - } - - return realElements; - } - - var strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get mustContainCommands() { return "Invalid HTML: AppBars/Menus must contain only AppBarCommands/MenuCommands"; }, - get closeOverlay() { return _Resources._getWinJSString("ui/closeOverlay").value; }, - }; - - var _Overlay = _Base.Class.define(function _Overlay_ctor(element, options) { - /// - /// - /// Constructs the Overlay control and associates it with the underlying DOM element. - /// - /// - /// The DOM element to be associated with the Overlay control. - /// - /// - /// The set of options to be applied initially to the Overlay control. - /// - /// A fully constructed Overlay control. - /// - this._baseOverlayConstructor(element, options); - }, { - // Functions/properties - _baseOverlayConstructor: function _Overlay_baseOverlayConstructor(element, options) { - - this._disposed = false; - - // Make sure there's an input element - if (!element) { - element = _Global.document.createElement("div"); - } - - // Check to make sure we weren't duplicated - var overlay = element.winControl; - if (overlay) { - throw new _ErrorFromName("WinJS.UI._Overlay.DuplicateConstruction", strings.duplicateConstruction); - } - - if (!this._element) { - this._element = element; - } - - if (!this._element.hasAttribute("tabIndex")) { - this._element.tabIndex = -1; - } - - this._sticky = false; - this._doNext = ""; - - this._element.style.visibility = "hidden"; - this._element.style.opacity = 0; - - // Remember ourselves - element.winControl = this; - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.overlayClass); - _ElementUtilities.addClass(this._element, "win-disposable"); - - // We don't want to be selectable, set UNSELECTABLE - var unselectable = this._element.getAttribute("unselectable"); - if (unselectable === null || unselectable === undefined) { - this._element.setAttribute("unselectable", "on"); - } - - // Base animation is popIn/popOut - this._currentAnimateIn = this._baseAnimateIn; - this._currentAnimateOut = this._baseAnimateOut; - this._animationPromise = Promise.as(); - - // Command Animations to Queue - this._queuedToShow = []; - this._queuedToHide = []; - this._queuedCommandAnimation = false; - - if (options) { - _Control.setOptions(this, options); - } - - // Make sure _Overlay event handlers are hooked up (this aids light dismiss) - _Overlay._globalEventListeners.initialize(); - }, - - /// - element: { - get: function () { - return this._element; - } - }, - - dispose: function () { - /// - /// - /// Disposes this Overlay. - /// - /// - if (this._disposed) { - return; - } - - this._disposed = true; - this._dispose(); - }, - - _dispose: function _Overlay_dispose() { - // To be overridden by subclasses - }, - - _show: function _Overlay_show() { - // We call our base _baseShow because AppBar may need to override show - this._baseShow(); - }, - - _hide: function _Overlay_hide() { - // We call our base _baseHide because AppBar may need to override hide - this._baseHide(); - }, - - // Is the overlay "hidden"? - /// - hidden: { - get: function () { - return (this._element.style.visibility === "hidden" || - this._element.winAnimating === "hiding" || - this._doNext === "hide"); - }, - set: function (hidden) { - var currentlyHidden = this.hidden; - if (!hidden && currentlyHidden) { - this._show(); - } else if (hidden && !currentlyHidden) { - this._hide(); - } - } - }, - - addEventListener: function (type, listener, useCapture) { - /// - /// - /// Add an event listener to the DOM element for this Overlay - /// - /// Required. Event type to add, "beforehide", "afterhide", "beforeshow", or "aftershow" - /// Required. The event handler function to associate with this event. - /// Optional. True, register for the event capturing phase. False for the event bubbling phase. - /// - return this._element.addEventListener(type, listener, useCapture); - }, - - removeEventListener: function (type, listener, useCapture) { - /// - /// - /// Remove an event listener to the DOM element for this Overlay - /// - /// Required. Event type to remove, "beforehide", "afterhide", "beforeshow", or "aftershow" - /// Required. The event handler function to associate with this event. - /// Optional. True, register for the event capturing phase. False for the event bubbling phase. - /// - return this._element.removeEventListener(type, listener, useCapture); - }, - - _baseShow: function _Overlay_baseShow() { - // If we are already animating, just remember this for later - if (this._animating || this._needToHandleHidingKeyboard) { - this._doNext = "show"; - return false; - } - - if (this._element.style.visibility !== "visible") { - // Let us know we're showing. - this._element.winAnimating = "showing"; - - // Hiding, but not none - this._element.style.display = ""; - this._element.style.visibility = "hidden"; - - // In case their event is going to manipulate commands, see if there are - // any queued command animations we can handle while we're still hidden. - if (this._queuedCommandAnimation) { - this._showAndHideFast(this._queuedToShow, this._queuedToHide); - this._queuedToShow = []; - this._queuedToHide = []; - } - - // Send our "beforeShow" event - this._sendEvent(_Overlay.beforeShow); - - // Need to measure - this._findPosition(); - - // Make sure it's visible, and fully opaque. - // Do the popup thing, sending event afterward. - var that = this; - this._animationPromise = this._currentAnimateIn(). - then(function () { - that._baseEndShow(); - }, function () { - that._baseEndShow(); - }); - return true; - } - return false; - }, - - // Flyout in particular will need to measure our positioning. - _findPosition: function _Overlay_findPosition() { - }, - - _baseEndShow: function _Overlay_baseEndShow() { - if (this._disposed) { - return; - } - - // Make sure it's visible after showing - this._element.setAttribute("aria-hidden", "false"); - - this._element.winAnimating = ""; - - // Do our derived classes show stuff - this._endShow(); - - // We're shown now - if (this._doNext === "show") { - this._doNext = ""; - } - - // After showing, send the after showing event - this._sendEvent(_Overlay.afterShow); - this._writeProfilerMark("show,StopTM"); // Overlay writes the stop profiler mark for all of its derived classes. - - // If we had something queued, do that - Scheduler.schedule(this._checkDoNext, Scheduler.Priority.normal, this, "WinJS.UI._Overlay._checkDoNext"); - - }, - - _endShow: function _Overlay_endShow() { - // Nothing by default - }, - - _baseHide: function _Overlay_baseHide() { - // If we are already animating, just remember this for later - if (this._animating) { - this._doNext = "hide"; - return false; - } - - // In the unlikely event we're between the hiding keyboard and the resize events, just snap it away: - if (this._needToHandleHidingKeyboard) { - // use the "uninitialized" flag - this._element.style.visibility = ""; - } - - if (this._element.style.visibility !== "hidden") { - // Let us know we're hiding, accessibility as well. - this._element.winAnimating = "hiding"; - this._element.setAttribute("aria-hidden", "true"); - - // Send our "beforeHide" event - this._sendEvent(_Overlay.beforeHide); - - // If our visibility is empty, then this is the first time, just hide it - if (this._element.style.visibility === "") { - // Initial hiding, just hide it - this._element.style.opacity = 0; - this._baseEndHide(); - } else { - // Make sure it's hidden, and fully transparent. - var that = this; - this._animationPromise = this._currentAnimateOut(). - then(function () { - that._baseEndHide(); - }, function () { - that._baseEndHide(); - }); - } - return true; - } - - return false; - }, - - _baseEndHide: function _Overlay_baseEndHide() { - if (this._disposed) { - return; - } - - // Do our derived classes hide stuff - this._beforeEndHide(); - - // Make sure animation is finished. - this._element.style.visibility = "hidden"; - this._element.style.display = "none"; - this._element.winAnimating = ""; - - // In case their event is going to manipulate commands, see if there - // are any queued command animations we can handle now we're hidden. - if (this._queuedCommandAnimation) { - this._showAndHideFast(this._queuedToShow, this._queuedToHide); - this._queuedToShow = []; - this._queuedToHide = []; - } - - // We're hidden now - if (this._doNext === "hide") { - this._doNext = ""; - } - - // After hiding, send our "afterHide" event - this._sendEvent(_Overlay.afterHide); - this._writeProfilerMark("hide,StopTM"); // Overlay writes the stop profiler mark for all of its derived classes. - - - // If we had something queued, do that. This has to be after - // the afterHide event in case it triggers a show() and they - // have something to do in beforeShow that requires afterHide first. - Scheduler.schedule(this._checkDoNext, Scheduler.Priority.normal, this, "WinJS.UI._Overlay._checkDoNext"); - }, - - // Called after the animation but while the Overlay is still visible. It's - // important that this runs while the Overlay is visible because hiding - // a DOM element (e.g. visibility="hidden", display="none") while it contains - // focus has the side effect of moving focus to the body or null and triggering - // focus move events. _beforeEndHide is a good hook for the Overlay to move focus - // elsewhere before its DOM element gets hidden. - _beforeEndHide: function _Overlay_beforeEndHide() { - // Nothing by default - }, - - _checkDoNext: function _Overlay_checkDoNext() { - // Do nothing if we're still animating - if (this._animating || this._needToHandleHidingKeyboard || this._disposed) { - return; - } - - if (this._doNext === "hide") { - // Do hide first because animating commands would be easier - this._hide(); - this._doNext = ""; - } else if (this._queuedCommandAnimation) { - // Do queued commands before showing if possible - this._showAndHideQueue(); - } else if (this._doNext === "show") { - // Show last so that we don't unnecessarily animate commands - this._show(); - this._doNext = ""; - } - }, - - // Default animations - _baseAnimateIn: function _Overlay_baseAnimateIn() { - this._element.style.opacity = 0; - this._element.style.visibility = "visible"; - // touch opacity so that IE fades from the 0 we just set to 1 - _Global.getComputedStyle(this._element, null).opacity; - return Animations.fadeIn(this._element); - }, - - _baseAnimateOut: function _Overlay_baseAnimateOut() { - this._element.style.opacity = 1; - // touch opacity so that IE fades from the 1 we just set to 0 - _Global.getComputedStyle(this._element, null).opacity; - return Animations.fadeOut(this._element); - }, - - _animating: { - get: function _Overlay_animating_get() { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return !!this._element.winAnimating; - } - }, - - // Send one of our events - _sendEvent: function _Overlay_sendEvent(eventName, detail) { - if (this._disposed) { - return; - } - var event = _Global.document.createEvent("CustomEvent"); - event.initEvent(eventName, true, true, (detail || {})); - this._element.dispatchEvent(event); - }, - - // Show commands - _showCommands: function _Overlay_showCommands(commands, immediate) { - var showHide = this._resolveCommands(commands); - this._showAndHideCommands(showHide.commands, [], immediate); - }, - - // Hide commands - _hideCommands: function _Overlay_hideCommands(commands, immediate) { - var showHide = this._resolveCommands(commands); - this._showAndHideCommands([], showHide.commands, immediate); - }, - - // Hide commands - _showOnlyCommands: function _Overlay_showOnlyCommands(commands, immediate) { - var showHide = this._resolveCommands(commands); - this._showAndHideCommands(showHide.commands, showHide.others, immediate); - }, - - _showAndHideCommands: function _Overlay_showAndHideCommands(showCommands, hideCommands, immediate) { - // Immediate is "easy" - if (immediate || (this.hidden && !this._animating)) { - // Immediate mode (not animated) - this._showAndHideFast(showCommands, hideCommands); - // Need to remove them from queues, but others could be queued - this._removeFromQueue(showCommands, this._queuedToShow); - this._removeFromQueue(hideCommands, this._queuedToHide); - } else { - - // Queue Commands - this._updateAnimateQueue(showCommands, this._queuedToShow, this._queuedToHide); - this._updateAnimateQueue(hideCommands, this._queuedToHide, this._queuedToShow); - } - }, - - _removeFromQueue: function _Overlay_removeFromQueue(commands, queue) { - // remove commands from queue. - var count; - for (count = 0; count < commands.length; count++) { - // Remove if it was in queue - var countQ; - for (countQ = 0; countQ < queue.length; countQ++) { - if (queue[countQ] === commands[count]) { - queue.splice(countQ, 1); - break; - } - } - } - }, - - _updateAnimateQueue: function _Overlay_updateAnimateQueue(addCommands, toQueue, fromQueue) { - if (this._disposed) { - return; - } - - // Add addCommands to toQueue and remove addCommands from fromQueue. - var count; - for (count = 0; count < addCommands.length; count++) { - // See if it's already in toQueue - var countQ; - for (countQ = 0; countQ < toQueue.length; countQ++) { - if (toQueue[countQ] === addCommands[count]) { - break; - } - } - if (countQ === toQueue.length) { - // Not found, add it - toQueue[countQ] = addCommands[count]; - } - // Remove if it was in fromQueue - for (countQ = 0; countQ < fromQueue.length; countQ++) { - if (fromQueue[countQ] === addCommands[count]) { - fromQueue.splice(countQ, 1); - break; - } - } - } - // If we haven't queued the actual animation - if (!this._queuedCommandAnimation) { - // If not already animating, we'll need to call _checkDoNext - if (!this._animating) { - Scheduler.schedule(this._checkDoNext, Scheduler.Priority.normal, this, "WinJS.UI._Overlay._checkDoNext"); - } - this._queuedCommandAnimation = true; - } - }, - - // show/hide commands without doing any animation. - _showAndHideFast: function _Overlay_showAndHideFast(showCommands, hideCommands) { - var count; - var command; - for (count = 0; count < showCommands.length; count++) { - command = showCommands[count]; - if (command && command.style) { - command.style.visibility = ""; - command.style.display = ""; - } - } - for (count = 0; count < hideCommands.length; count++) { - command = hideCommands[count]; - if (command && command.style) { - command.style.visibility = "hidden"; - command.style.display = "none"; - } - } - - this._commandsUpdated(); - - }, - - // show and hide the queued commands, perhaps animating if overlay isn't hidden. - _showAndHideQueue: function _Overlay_showAndHideQueue() { - // Only called if not currently animating. - // We'll be done with the queued stuff when we return. - this._queuedCommandAnimation = false; - - // Shortcut if hidden - if (this.hidden) { - this._showAndHideFast(this._queuedToShow, this._queuedToHide); - // Might be something else to do - Scheduler.schedule(this._checkDoNext, Scheduler.Priority.normal, this, "WinJS.UI._Overlay._checkDoNext"); - } else { - // Animation has 3 parts: "hiding", "showing", and "moving" - // PVL has "addToList" and "deleteFromList", both of which allow moving parts. - // So we'll set up "add" for showing, and use "delete" for "hiding" + moving, - // then trigger both at the same time. - var showCommands = this._queuedToShow; - var hideCommands = this._queuedToHide; - var siblings = this._findSiblings(showCommands.concat(hideCommands)); - - // Filter out the commands queued for animation that don't need to be animated. - var count; - for (count = 0; count < showCommands.length; count++) { - // If this one's not real or not attached, skip it - if (!showCommands[count] || - !showCommands[count].style || - !_Global.document.body.contains(showCommands[count])) { - // Not real, skip it - showCommands.splice(count, 1); - count--; - } else if (showCommands[count].style.visibility !== "hidden" && showCommands[count].style.opacity !== "0") { - // Don't need to animate showing this one, already visible, so now it's a sibling - siblings.push(showCommands[count]); - showCommands.splice(count, 1); - count--; - } - } - for (count = 0; count < hideCommands.length; count++) { - // If this one's not real or not attached, skip it - if (!hideCommands[count] || - !hideCommands[count].style || - !_Global.document.body.contains(hideCommands[count]) || - hideCommands[count].style.visibility === "hidden" || - hideCommands[count].style.opacity === "0") { - // Don't need to animate hiding this one, not real, or it's hidden, - // so don't even need it as a sibling. - hideCommands.splice(count, 1); - count--; - } - } - - // Start command animations. - var commandsAnimationPromise = this._baseBeginAnimateCommands(showCommands, hideCommands, siblings); - - // Hook end animations - var that = this; - if (commandsAnimationPromise) { - // Needed to animate - commandsAnimationPromise.done( - function () { that._baseEndAnimateCommands(hideCommands); }, - function () { that._baseEndAnimateCommands(hideCommands); } - ); - } else { - // Already positioned correctly - Scheduler.schedule(function Overlay_async_baseEndAnimationCommands() { that._baseEndAnimateCommands([]); }, - Scheduler.Priority.normal, null, - "WinJS.UI._Overlay._endAnimateCommandsWithoutAnimation"); - } - } - - // Done, clear queues - this._queuedToShow = []; - this._queuedToHide = []; - }, - - _baseBeginAnimateCommands: function _Overlay_baseBeginAnimateCommands(showCommands, hideCommands, siblings) { - // The parameters are 3 mutually exclusive arrays of win-command elements contained in this Overlay. - // 1) showCommands[]: All of the HIDDEN win-command elements that ARE scheduled to show. - // 2) hideCommands[]: All of the VISIBLE win-command elements that ARE shceduled to hide. - // 3) siblings[]: i. All VISIBLE win-command elements that ARE NOT scheduled to hide. - // ii. All HIDDEN win-command elements that ARE NOT scheduled to hide OR show. - this._beginAnimateCommands(showCommands, hideCommands, this._getVisibleCommands(siblings)); - - var showAnimated = null, - hideAnimated = null; - - // Hide commands first, with siblings if necessary, - // so that the showing commands don't disrupt the hiding commands position. - if (hideCommands.length > 0) { - hideAnimated = Animations.createDeleteFromListAnimation(hideCommands, showCommands.length === 0 ? siblings : undefined); - } - if (showCommands.length > 0) { - showAnimated = Animations.createAddToListAnimation(showCommands, siblings); - } - - // Update hiding commands - for (var count = 0, len = hideCommands.length; count < len; count++) { - // Need to fix our position - var rectangle = hideCommands[count].getBoundingClientRect(), - style = _Global.getComputedStyle(hideCommands[count]); - - // Use the bounding box, adjusting for margins - hideCommands[count].style.top = (rectangle.top - parseFloat(style.marginTop)) + "px"; - hideCommands[count].style.left = (rectangle.left - parseFloat(style.marginLeft)) + "px"; - hideCommands[count].style.opacity = 0; - hideCommands[count].style.position = "fixed"; - } - - // Mark as animating - this._element.winAnimating = "rearranging"; - - // Start hiding animations - // Hide needs extra cleanup when done - var promise = null; - if (hideAnimated) { - promise = hideAnimated.execute(); - } - - // Update showing commands, - // After hiding commands so that the hiding ones fade in the right place. - for (count = 0; count < showCommands.length; count++) { - showCommands[count].style.visibility = ""; - showCommands[count].style.display = ""; - showCommands[count].style.opacity = 1; - } - - // Start showing animations - if (showAnimated) { - var newPromise = showAnimated.execute(); - if (promise) { - promise = Promise.join([promise, newPromise]); - } else { - promise = newPromise; - } - } - - return promise; - }, - - _beginAnimateCommands: function _Overlay_beginAnimateCommands() { - // Nothing by default - }, - - _getVisibleCommands: function _Overlay_getVisibleCommands(commandSubSet) { - var command, - commands = commandSubSet, - visibleCommands = []; - - if (!commands) { - // Crawl the inner HTML for the commands. - commands = this.element.querySelectorAll(".win-command"); - } - - for (var i = 0, len = commands.length; i < len; i++) { - command = commands[i].winControl || commands[i]; - if (!command.hidden) { - visibleCommands.push(command); - } - } - - return visibleCommands; - }, - - // Once animation is complete, ensure that the commands are display:none - // and check if there's another animation to start. - _baseEndAnimateCommands: function _Overlay_baseEndAnimateCommands(hideCommands) { - if (this._disposed) { - return; - } - - // Update us - var count; - for (count = 0; count < hideCommands.length; count++) { - // Force us back into our appbar so that we can show again correctly - hideCommands[count].style.position = ""; - hideCommands[count].style.top = ""; - hideCommands[count].style.left = ""; - hideCommands[count].getBoundingClientRect(); - // Now make us really hidden - hideCommands[count].style.visibility = "hidden"; - hideCommands[count].style.display = "none"; - hideCommands[count].style.opacity = 1; - } - // Done animating - this._element.winAnimating = ""; - - this._endAnimateCommands(); - - // Might be something else to do - this._checkDoNext(); - }, - - _endAnimateCommands: function _Overlay_endAnimateCommands() { - // Nothing by default - }, - - // Resolves our commands - _resolveCommands: function _Overlay_resolveCommands(commands) { - // First make sure they're all DOM elements. - commands = _resolveElements(commands); - - // Now make sure they're all in this container - var result = {}; - result.commands = []; - result.others = []; - var allCommands = this.element.querySelectorAll(".win-command"); - var countAll, countIn; - for (countAll = 0; countAll < allCommands.length; countAll++) { - var found = false; - for (countIn = 0; countIn < commands.length; countIn++) { - if (commands[countIn] === allCommands[countAll]) { - result.commands.push(allCommands[countAll]); - commands.splice(countIn, 1); - found = true; - break; - } - } - if (!found) { - result.others.push(allCommands[countAll]); - } - } - return result; - }, - - // Find siblings, all DOM elements now. - // Returns all .win-commands in this Overlay that are NOT in the passed in 'commands' array. - _findSiblings: function _Overlay_findSiblings(commands) { - // Now make sure they're all in this container - var siblings = []; - var allCommands = this.element.querySelectorAll(".win-command"); - var countAll, countIn; - for (countAll = 0; countAll < allCommands.length; countAll++) { - var found = false; - for (countIn = 0; countIn < commands.length; countIn++) { - if (commands[countIn] === allCommands[countAll]) { - commands.splice(countIn, 1); - found = true; - break; - } - } - if (!found) { - siblings.push(allCommands[countAll]); - } - } - return siblings; - }, - - _baseResize: function _Overlay_baseResize(event) { - // Call specific resize - this._resize(event); - }, - - _hideOrDismiss: function _Overlay_hideOrDismiss() { - var element = this._element; - if (element && _ElementUtilities.hasClass(element, _Constants.settingsFlyoutClass)) { - this._dismiss(); - } else if (element && _ElementUtilities.hasClass(element, _Constants.appBarClass)) { - this.close(); - } else { - this.hide(); - } - }, - - _resize: function _Overlay_resize() { - // Nothing by default - }, - - _commandsUpdated: function _Overlay_commandsUpdated() { - // Nothing by default - }, - - _checkScrollPosition: function _Overlay_checkScrollPosition() { - // Nothing by default - }, - - _showingKeyboard: function _Overlay_showingKeyboard() { - // Nothing by default - }, - - _hidingKeyboard: function _Overlay_hidingKeyboard() { - // Nothing by default - }, - - // Verify that this HTML AppBar only has AppBar/MenuCommands. - _verifyCommandsOnly: function _Overlay_verifyCommandsOnly(element, type) { - var children = element.children; - var commands = new Array(children.length); - for (var i = 0; i < children.length; i++) { - // If constructed they have win-command class, otherwise they have data-win-control - if (!_ElementUtilities.hasClass(children[i], "win-command") && - children[i].getAttribute("data-win-control") !== type) { - // Wasn't tagged with class or AppBar/MenuCommand, not an AppBar/MenuCommand - throw new _ErrorFromName("WinJS.UI._Overlay.MustContainCommands", strings.mustContainCommands); - } else { - // Instantiate the commands. - ControlProcessor.processAll(children[i]); - commands[i] = children[i].winControl; - } - } - return commands; - }, - - // Sets focus on what we think is the last tab stop. If nothing is focusable will - // try to set focus on itself. - _focusOnLastFocusableElementOrThis: function _Overlay_focusOnLastFocusableElementOrThis() { - if (!this._focusOnLastFocusableElement()) { - // Nothing is focusable. Set focus to this. - _Overlay._trySetActive(this._element); - } - }, - - // Sets focus to what we think is the last tab stop. This element must have - // a firstDiv with tabIndex equal to the lowest tabIndex in the element - // and a finalDiv with tabIndex equal to the highest tabIndex in the element. - // Also the firstDiv must be its first child and finalDiv be its last child. - // Returns true if successful, false otherwise. - _focusOnLastFocusableElement: function _Overlay_focusOnLastFocusableElement() { - if (this._element.firstElementChild) { - var oldFirstTabIndex = this._element.firstElementChild.tabIndex; - var oldLastTabIndex = this._element.lastElementChild.tabIndex; - this._element.firstElementChild.tabIndex = -1; - this._element.lastElementChild.tabIndex = -1; - - var tabResult = _ElementUtilities._focusLastFocusableElement(this._element); - - if (tabResult) { - _Overlay._trySelect(_Global.document.activeElement); - } - - this._element.firstElementChild.tabIndex = oldFirstTabIndex; - this._element.lastElementChild.tabIndex = oldLastTabIndex; - - return tabResult; - } else { - return false; - } - }, - - - // Sets focus on what we think is the first tab stop. If nothing is focusable will - // try to set focus on itself. - _focusOnFirstFocusableElementOrThis: function _Overlay_focusOnFirstFocusableElementOrThis() { - if (!this._focusOnFirstFocusableElement()) { - // Nothing is focusable. Set focus to this. - _Overlay._trySetActive(this._element); - } - }, - - // Sets focus to what we think is the first tab stop. This element must have - // a firstDiv with tabIndex equal to the lowest tabIndex in the element - // and a finalDiv with tabIndex equal to the highest tabIndex in the element. - // Also the firstDiv must be its first child and finalDiv be its last child. - // Returns true if successful, false otherwise. - _focusOnFirstFocusableElement: function _Overlay__focusOnFirstFocusableElement(useSetActive, scroller) { - if (this._element.firstElementChild) { - var oldFirstTabIndex = this._element.firstElementChild.tabIndex; - var oldLastTabIndex = this._element.lastElementChild.tabIndex; - this._element.firstElementChild.tabIndex = -1; - this._element.lastElementChild.tabIndex = -1; - - var tabResult = _ElementUtilities._focusFirstFocusableElement(this._element, useSetActive, scroller); - - if (tabResult) { - _Overlay._trySelect(_Global.document.activeElement); - } - - this._element.firstElementChild.tabIndex = oldFirstTabIndex; - this._element.lastElementChild.tabIndex = oldLastTabIndex; - - return tabResult; - } else { - return false; - } - }, - - _writeProfilerMark: function _Overlay_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI._Overlay:" + this._id + ":" + text); - } - }, - { - // Statics - - _isFlyoutVisible: function () { - var flyouts = _Global.document.querySelectorAll("." + _Constants.flyoutClass); - for (var i = 0; i < flyouts.length; i++) { - var flyoutControl = flyouts[i].winControl; - if (flyoutControl && !flyoutControl.hidden) { - return true; - } - } - - return false; - }, - - // Try to set us as active - _trySetActive: function (element, scroller) { - if (!element || !_Global.document.body || !_Global.document.body.contains(element)) { - return false; - } - if (!_ElementUtilities._setActive(element, scroller)) { - return false; - } - return (element === _Global.document.activeElement); - }, - - // Try to select the text so keyboard can be used. - _trySelect: function (element) { - try { - if (element && element.select) { - element.select(); - } - } catch (e) { } - }, - - _sizeOfDocument: function () { - return { - width: _Global.document.documentElement.offsetWidth, - height: _Global.document.documentElement.offsetHeight, - }; - }, - - _getParentControlUsingClassName: function (element, className) { - while (element && element !== _Global.document.body) { - if (_ElementUtilities.hasClass(element, className)) { - return element.winControl; - } - element = element.parentNode; - } - return null; - }, - - // Static controller for _Overlay global events registering/unregistering. - _globalEventListeners: new _GlobalListener(), - - // Show/Hide all bars - _hideAppBars: function _Overlay_hideAppBars(bars, keyboardInvoked) { - var allBarsAnimationPromises = bars.map(function (bar) { - bar.close(); - return bar._animationPromise; - }); - return Promise.join(allBarsAnimationPromises); - }, - - _showAppBars: function _Overlay_showAppBars(bars, keyboardInvoked) { - var allBarsAnimationPromises = bars.map(function (bar) { - bar._show(); - return bar._animationPromise; - }); - return Promise.join(allBarsAnimationPromises); - }, - - // WWA Soft Keyboard offsets - _keyboardInfo: _KeyboardInfo._KeyboardInfo, - - // Padding for IHM timer to allow for first scroll event - _scrollTimeout: _KeyboardInfo._KeyboardInfo._scrollTimeout, - - // Events - beforeShow: "beforeshow", - beforeHide: "beforehide", - afterShow: "aftershow", - afterHide: "afterhide", - - commonstrings: { - get cannotChangeCommandsWhenVisible() { return "Invalid argument: You must call hide() before changing {0} commands"; }, - get cannotChangeHiddenProperty() { return "Unable to set hidden property while parent {0} is visible."; } - }, - }); - - _Base.Class.mix(_Overlay, _Control.DOMEventMixin); - - return _Overlay; - }) - }); - -}); - - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// appbar,Flyout,Flyouts,Statics -define('WinJS/Controls/Flyout',[ - 'exports', - '../Core/_Global', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Events', - '../Core/_Log', - '../Core/_Resources', - '../Core/_WriteProfilerMark', - '../Animations', - '../_Signal', - '../_LightDismissService', - '../Utilities/_Dispose', - '../Utilities/_ElementUtilities', - '../Utilities/_KeyboardBehavior', - '../Utilities/_Hoverable', - './_LegacyAppBar/_Constants', - './Flyout/_Overlay' -], function flyoutInit(exports, _Global, _Base, _BaseUtils, _ErrorFromName, _Events, _Log, _Resources, _WriteProfilerMark, Animations, _Signal, _LightDismissService, _Dispose, _ElementUtilities, _KeyboardBehavior, _Hoverable, _Constants, _Overlay) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// Displays lightweight UI that is either informational, or requires user interaction. - /// Unlike a dialog, a Flyout can be light dismissed by clicking or tapping off of it. - /// - /// - /// - /// Flyout - /// - /// - /// ]]> - /// Raised just before showing a flyout. - /// Raised immediately after a flyout is fully shown. - /// Raised just before hiding a flyout. - /// Raised immediately after a flyout is fully hidden. - /// The Flyout control itself. - /// - /// - Flyout: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - function getDimension(element, property) { - return _ElementUtilities.convertToPixels(element, _Global.getComputedStyle(element, null)[property]); - } - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/flyoutAriaLabel").value; }, - get noAnchor() { return "Invalid argument: Flyout anchor element not found in DOM."; }, - get badPlacement() { return "Invalid argument: Flyout placement should be 'top' (default), 'bottom', 'left', 'right', 'auto', 'autohorizontal', or 'autovertical'."; }, - get badAlignment() { return "Invalid argument: Flyout alignment should be 'center' (default), 'left', or 'right'."; } - }; - - var createEvent = _Events._createEventProperty; - - // _LightDismissableLayer is an ILightDismissable which manages a set of ILightDismissables. - // It acts as a proxy between the LightDismissService and the light dismissables it manages. - // It enables multiple dismissables to be above the click eater at the same time. - var _LightDismissableLayer = _Base.Class.define(function _LightDismissableLayer_ctor(onLightDismiss) { - this._onLightDismiss = onLightDismiss; - this._currentlyFocusedClient = null; - this._clients = []; // Array of ILightDismissables - }, { - // Dismissables should call this as soon as they are ready to be shown. More specifically, they should call this: - // - After they are in the DOM and ready to receive focus (e.g. style.display cannot be "none") - // - Before their entrance animation is played - shown: function _LightDismissableLayer_shown(client /*: ILightDismissable */) { - client._focusable = true; - var index = this._clients.indexOf(client); - if (index === -1) { - this._clients.push(client); - client.onShow(this); - if (!_LightDismissService.isShown(this)) { - _LightDismissService.shown(this); - } else { - _LightDismissService.updated(this); - this._activateTopFocusableClientIfNeeded(); - } - } - }, - - // Dismissables should call this at the start of their exit animation. A "hiding", - // dismissable will still be rendered with the proper z-index but it will no - // longer be given focus. Also, focus is synchronously moved out of this dismissable. - hiding: function _LightDismissableLayer_hiding(client /*: ILightDismissable */) { - var index = this._clients.indexOf(client); - if (index !== -1) { - this._clients[index]._focusable = false; - this._activateTopFocusableClientIfNeeded(); - } - }, - - // Dismissables should call this when they are done being dismissed (i.e. after their exit animation has finished) - hidden: function _LightDismissableLayer_hidden(client /*: ILightDismissable */) { - var index = this._clients.indexOf(client); - if (index !== -1) { - this._clients.splice(index, 1); - client.setZIndex(""); - client.onHide(); - if (this._clients.length === 0) { - _LightDismissService.hidden(this); - } else { - _LightDismissService.updated(this); - this._activateTopFocusableClientIfNeeded(); - } - } - }, - - keyDown: function _LightDismissableLayer_keyDown(client /*: ILightDismissable */, eventObject) { - _LightDismissService.keyDown(this, eventObject); - }, - keyUp: function _LightDismissableLayer_keyUp(client /*: ILightDismissable */, eventObject) { - _LightDismissService.keyUp(this, eventObject); - }, - keyPress: function _LightDismissableLayer_keyPress(client /*: ILightDismissable */, eventObject) { - _LightDismissService.keyPress(this, eventObject); - }, - - // Used by tests. - clients: { - get: function _LightDismissableLayer_clients_get() { - return this._clients; - } - }, - - _clientForElement: function _LightDismissableLayer_clientForElement(element) { - for (var i = this._clients.length - 1; i >= 0; i--) { - if (this._clients[i].containsElement(element)) { - return this._clients[i]; - } - } - return null; - }, - - _focusableClientForElement: function _LightDismissableLayer_focusableClientForElement(element) { - for (var i = this._clients.length - 1; i >= 0; i--) { - if (this._clients[i]._focusable && this._clients[i].containsElement(element)) { - return this._clients[i]; - } - } - return null; - }, - - _getTopmostFocusableClient: function _LightDismissableLayer_getTopmostFocusableClient() { - for (var i = this._clients.length - 1; i >= 0; i--) { - var client = this._clients[i]; - if (client && client._focusable) { - return client; - } - } - return null; - }, - - _activateTopFocusableClientIfNeeded: function _LightDismissableLayer_activateTopFocusableClientIfNeeded() { - var topClient = this._getTopmostFocusableClient(); - if (topClient && _LightDismissService.isTopmost(this)) { - // If the last input type was keyboard, use focus() so a keyboard focus visual is drawn. - // Otherwise, use setActive() so no focus visual is drawn. - var useSetActive = !_KeyboardBehavior._keyboardSeenLast; - topClient.onTakeFocus(useSetActive); - } - }, - - // ILightDismissable - // - - setZIndex: function _LightDismissableLayer_setZIndex(zIndex) { - this._clients.forEach(function (client, index) { - client.setZIndex(zIndex + index); - }, this); - }, - getZIndexCount: function _LightDismissableLayer_getZIndexCount() { - return this._clients.length; - }, - containsElement: function _LightDismissableLayer_containsElement(element) { - return !!this._clientForElement(element); - }, - onTakeFocus: function _LightDismissableLayer_onTakeFocus(useSetActive) { - // Prefer the client that has focus - var client = this._focusableClientForElement(_Global.document.activeElement); - - if (!client && this._clients.indexOf(this._currentlyFocusedClient) !== -1 && this._currentlyFocusedClient._focusable) { - // Next try the client that had focus most recently - client = this._currentlyFocusedClient; - } - - if (!client) { - // Finally try the client at the top of the stack - client = this._getTopmostFocusableClient(); - } - - this._currentlyFocusedClient = client; - client && client.onTakeFocus(useSetActive); - }, - onFocus: function _LightDismissableLayer_onFocus(element) { - this._currentlyFocusedClient = this._clientForElement(element); - this._currentlyFocusedClient && this._currentlyFocusedClient.onFocus(element); - }, - onShow: function _LightDismissableLayer_onShow(service /*: ILightDismissService */) { }, - onHide: function _LightDismissableLayer_onHide() { - this._currentlyFocusedClient = null; - }, - onKeyInStack: function _LightDismissableLayer_onKeyInStack(info /*: IKeyboardInfo*/) { - // A keyboard event occurred in the light dismiss stack. Notify the flyouts to - // give them the opportunity to handle this evnet. - var index = this._clients.indexOf(this._currentlyFocusedClient); - if (index !== -1) { - var clients = this._clients.slice(0, index + 1); - for (var i = clients.length - 1; i >= 0 && !info.propagationStopped; i--) { - if (clients[i]._focusable) { - clients[i].onKeyInStack(info); - } - } - } - }, - onShouldLightDismiss: function _LightDismissableLayer_onShouldLightDismiss(info) { - return _LightDismissService.DismissalPolicies.light(info); - }, - onLightDismiss: function _LightDismissableLayer_onLightDismiss(info) { - this._onLightDismiss(info); - } - }); - - // Singleton class for managing cascading flyouts - var _CascadeManager = _Base.Class.define(function _CascadeManager_ctor() { - var that = this; - this._dismissableLayer = new _LightDismissableLayer(function _CascadeManager_onLightDismiss(info) { - if (info.reason === _LightDismissService.LightDismissalReasons.escape) { - that.collapseFlyout(that.getAt(that.length - 1)); - } else { - that.collapseAll(); - } - }); - this._cascadingStack = []; - this._handleKeyDownInCascade_bound = this._handleKeyDownInCascade.bind(this); - this._inputType = null; - }, - { - appendFlyout: function _CascadeManager_appendFlyout(flyoutToAdd) { - // PRECONDITION: flyoutToAdd must not already be in the cascade. - _Log.log && this.indexOf(flyoutToAdd) >= 0 && _Log.log('_CascadeManager is attempting to append a Flyout that is already in the cascade.', "winjs _CascadeManager", "error"); - // PRECONDITION: this.reentrancyLock must be false. appendFlyout should only be called from baseFlyoutShow() which is the function responsible for preventing reentrancy. - _Log.log && this.reentrancyLock && _Log.log('_CascadeManager is attempting to append a Flyout through reentrancy.', "winjs _CascadeManager", "error"); - - // IF the anchor element for flyoutToAdd is contained within another flyout, - // && that flyout is currently in the cascadingStack, consider that flyout to be the parent of flyoutToAdd: - // Remove from the cascadingStack, any subflyout descendants of the parent flyout. - // ELSE flyoutToAdd isn't anchored to any of the Flyouts in the existing cascade - // Collapse the entire cascadingStack to start a new cascade. - // FINALLY: - // add flyoutToAdd to the end of the cascading stack. Monitor it for events. - var indexOfParentFlyout = this.indexOfElement(flyoutToAdd._currentAnchor); - if (indexOfParentFlyout >= 0) { - this.collapseFlyout(this.getAt(indexOfParentFlyout + 1)); - } else { - this.collapseAll(); - } - - flyoutToAdd.element.addEventListener("keydown", this._handleKeyDownInCascade_bound, false); - this._cascadingStack.push(flyoutToAdd); - this._dismissableLayer.shown(flyoutToAdd._dismissable); - }, - collapseFlyout: function _CascadeManager_collapseFlyout(flyout) { - // Removes flyout param and its subflyout descendants from the _cascadingStack. - if (!this.reentrancyLock && flyout && this.indexOf(flyout) >= 0) { - this.reentrancyLock = true; - var signal = new _Signal(); - this.unlocked = signal.promise; - - var subFlyout; - while (this.length && flyout !== subFlyout) { - subFlyout = this._cascadingStack.pop(); - subFlyout.element.removeEventListener("keydown", this._handleKeyDownInCascade_bound, false); - subFlyout._hide(); // We use the reentrancyLock to prevent reentrancy here. - } - - if (this._cascadingStack.length === 0) { - // The cascade is empty so clear the input type. This gives us the opportunity - // to recalculate the input type when the next cascade starts. - this._inputType = null; - } - - this.reentrancyLock = false; - this.unlocked = null; - signal.complete(); - } - }, - flyoutHiding: function _CascadeManager_flyoutHiding(flyout) { - this._dismissableLayer.hiding(flyout._dismissable); - }, - flyoutHidden: function _CascadeManager_flyoutHidden(flyout) { - this._dismissableLayer.hidden(flyout._dismissable); - }, - collapseAll: function _CascadeManager_collapseAll() { - // Empties the _cascadingStack and hides all flyouts. - var headFlyout = this.getAt(0); - if (headFlyout) { - this.collapseFlyout(headFlyout); - } - }, - indexOf: function _CascadeManager_indexOf(flyout) { - return this._cascadingStack.indexOf(flyout); - }, - indexOfElement: function _CascadeManager_indexOfElement(el) { - // Returns an index cooresponding to the Flyout in the cascade whose element contains the element in question. - // Returns -1 if the element is not contained by any Flyouts in the cascade. - var indexOfAssociatedFlyout = -1; - for (var i = 0, len = this.length; i < len; i++) { - var currentFlyout = this.getAt(i); - if (currentFlyout.element.contains(el)) { - indexOfAssociatedFlyout = i; - break; - } - } - return indexOfAssociatedFlyout; - }, - length: { - get: function _CascadeManager_getLength() { - return this._cascadingStack.length; - } - }, - getAt: function _CascadeManager_getAt(index) { - return this._cascadingStack[index]; - }, - handleFocusIntoFlyout: function _CascadeManager_handleFocusIntoFlyout(event) { - // When a flyout in the cascade recieves focus, we close all subflyouts beneath it. - var index = this.indexOfElement(event.target); - if (index >= 0) { - var subFlyout = this.getAt(index + 1); - this.collapseFlyout(subFlyout); - } - }, - // Compute the input type that is associated with the cascading stack on demand. Allows - // each Flyout in the cascade to adjust its sizing based on the current input type - // and to do it in a way that is consistent with the rest of the Flyouts in the cascade. - inputType: { - get: function _CascadeManager_inputType_get() { - if (!this._inputType) { - this._inputType = _KeyboardBehavior._lastInputType; - } - return this._inputType; - } - }, - // Used by tests. - dismissableLayer: { - get: function _CascadeManager_dismissableLayer_get() { - return this._dismissableLayer; - } - }, - _handleKeyDownInCascade: function _CascadeManager_handleKeyDownInCascade(event) { - var rtl = _Global.getComputedStyle(event.target).direction === "rtl", - leftKey = rtl ? Key.rightArrow : Key.leftArrow, - target = event.target; - - if (event.keyCode === leftKey) { - // Left key press in a SubFlyout will close that subFlyout and any subFlyouts cascading from it. - var index = this.indexOfElement(target); - if (index >= 1) { - var subFlyout = this.getAt(index); - this.collapseFlyout(subFlyout); - // Prevent document scrolling - event.preventDefault(); - } - } else if (event.keyCode === Key.alt || event.keyCode === Key.F10) { - this.collapseAll(); - } - } - }); - - var AnimationOffsets = { - top: { top: "50px", left: "0px", keyframe: "WinJS-showFlyoutTop" }, - bottom: { top: "-50px", left: "0px", keyframe: "WinJS-showFlyoutBottom" }, - left: { top: "0px", left: "50px", keyframe: "WinJS-showFlyoutLeft" }, - right: { top: "0px", left: "-50px", keyframe: "WinJS-showFlyoutRight" }, - }; - - var Flyout = _Base.Class.derive(_Overlay._Overlay, function Flyout_ctor(element, options) { - /// - /// - /// Creates a new Flyout control. - /// - /// - /// The DOM element that hosts the control. - /// - /// - /// The set of properties and values to apply to the new Flyout. - /// - /// The new Flyout control. - /// - /// - - // Simplify checking later - options = options || {}; - - // Make sure there's an input element - this._element = element || _Global.document.createElement("div"); - this._id = this._element.id || _ElementUtilities._uniqueID(this._element); - this._writeProfilerMark("constructor,StartTM"); - - this._baseFlyoutConstructor(this._element, options); - - var _elms = this._element.getElementsByTagName("*"); - var firstDiv = this._addFirstDiv(); - firstDiv.tabIndex = _ElementUtilities._getLowestTabIndexInList(_elms); - var finalDiv = this._addFinalDiv(); - finalDiv.tabIndex = _ElementUtilities._getHighestTabIndexInList(_elms); - - // Handle "esc" & "tab" key presses - this._element.addEventListener("keydown", this._handleKeyDown, true); - - this._writeProfilerMark("constructor,StopTM"); - return this; - }, { - _lastMaxHeight: null, - - _baseFlyoutConstructor: function Flyout_baseFlyoutContstructor(element, options) { - // Flyout constructor - - // We have some options with defaults - this._placement = "auto"; - this._alignment = "center"; - - // Call the base overlay constructor helper - this._baseOverlayConstructor(element, options); - - // Start flyouts hidden - this._element.style.visibilty = "hidden"; - this._element.style.display = "none"; - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.flyoutClass); - - var that = this; - // Each flyout has an ILightDismissable that is managed through the - // CascasdeManager rather than by the _LightDismissService directly. - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._element, - tabIndex: this._element.hasAttribute("tabIndex") ? this._element.tabIndex : -1, - onLightDismiss: function () { - that.hide(); - }, - onTakeFocus: function (useSetActive) { - if (!that._dismissable.restoreFocus()) { - if (!_ElementUtilities.hasClass(that.element, _Constants.menuClass)) { - // Put focus on the first child in the Flyout - that._focusOnFirstFocusableElementOrThis(); - } else { - // Make sure the menu has focus, but don't show a focus rect - _Overlay._Overlay._trySetActive(that._element); - } - } - } - }); - - // Make sure we have an ARIA role - var role = this._element.getAttribute("role"); - if (role === null || role === "" || role === undefined) { - if (_ElementUtilities.hasClass(this._element, _Constants.menuClass)) { - this._element.setAttribute("role", "menu"); - } else { - this._element.setAttribute("role", "dialog"); - } - } - var label = this._element.getAttribute("aria-label"); - if (label === null || label === "" || label === undefined) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - - // Base animation is popIn, but our flyout has different arguments - this._currentAnimateIn = this._flyoutAnimateIn; - this._currentAnimateOut = this._flyoutAnimateOut; - - _ElementUtilities._addEventListener(this.element, "focusin", this._handleFocusIn.bind(this), false); - }, - - /// - /// Gets or sets the Flyout control's anchor. The anchor element is the HTML element which the Flyout originates from and is positioned relative to. - /// (This setting can be overridden when you call the show method.) - /// - /// - anchor: { - get: function () { - return this._anchor; - }, - set: function (value) { - this._anchor = value; - } - }, - - /// - /// Gets or sets the default placement of this Flyout. (This setting can be overridden when you call the show method.) - /// - /// - placement: { - get: function () { - return this._placement; - }, - set: function (value) { - if (value !== "top" && value !== "bottom" && value !== "left" && value !== "right" && value !== "auto" && value !== "autohorizontal" && value !== "autovertical") { - // Not a legal placement value - throw new _ErrorFromName("WinJS.UI.Flyout.BadPlacement", strings.badPlacement); - } - this._placement = value; - } - }, - - /// - /// Gets or sets the default alignment for this Flyout. (This setting can be overridden when you call the show method.) - /// - /// - alignment: { - get: function () { - return this._alignment; - }, - set: function (value) { - if (value !== "right" && value !== "left" && value !== "center") { - // Not a legal alignment value - throw new _ErrorFromName("WinJS.UI.Flyout.BadAlignment", strings.badAlignment); - } - this._alignment = value; - } - }, - - /// Disable a Flyout, setting or getting the HTML disabled attribute. When disabled the Flyout will no longer display with show(), and will hide if currently visible. - disabled: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return !!this._element.disabled; - }, - set: function (value) { - // Force this check into a boolean because our current state could be a bit confused since we tie to the DOM element - value = !!value; - var oldValue = !!this._element.disabled; - if (oldValue !== value) { - this._element.disabled = value; - if (!this.hidden && this._element.disabled) { - this.hide(); - } - } - } - }, - - /// - /// Occurs immediately before the control is shown. - /// - onbeforeshow: createEvent(_Overlay._Overlay.beforeShow), - - /// - /// Occurs immediately after the control is shown. - /// - onaftershow: createEvent(_Overlay._Overlay.afterShow), - - /// - /// Occurs immediately before the control is hidden. - /// - onbeforehide: createEvent(_Overlay._Overlay.beforeHide), - - /// - /// Occurs immediately after the control is hidden. - /// - onafterhide: createEvent(_Overlay._Overlay.afterHide), - - _dispose: function Flyout_dispose() { - _Dispose.disposeSubTree(this.element); - this._hide(); - Flyout._cascadeManager.flyoutHidden(this); - this.anchor = null; - }, - - show: function (anchor, placement, alignment) { - /// - /// - /// Shows the Flyout, if hidden, regardless of other states. - /// - /// - /// The DOM element, or ID of a DOM element to anchor the Flyout, overriding the anchor property for this time only. - /// - /// - /// The placement of the Flyout to the anchor: 'auto' (default), 'top', 'bottom', 'left', or 'right'. This parameter overrides the placement property for this show only. - /// - /// - /// For 'top' or 'bottom' placement, the alignment of the Flyout to the anchor's edge: 'center' (default), 'left', or 'right'. - /// This parameter overrides the alignment property for this show only. - /// - /// - /// - this._writeProfilerMark("show,StartTM"); // The corresponding "stop" profiler mark is handled in _Overlay._baseEndShow(). - this._show(anchor, placement, alignment); - }, - - _show: function Flyout_show(anchor, placement, alignment) { - this._baseFlyoutShow(anchor, placement, alignment); - }, - - hide: function () { - /// - /// - /// Hides the Flyout, if visible, regardless of other states. - /// - /// - /// - // Just wrap the private one, turning off keyboard invoked flag - this._writeProfilerMark("hide,StartTM"); // The corresponding "stop" profiler mark is handled in _Overlay._baseEndHide(). - this._hide(); - }, - - _hide: function Flyout_hide() { - - // First close all subflyout descendants in the cascade. - // Any calls to collapseFlyout through reentrancy should nop. - Flyout._cascadeManager.collapseFlyout(this); - - if (this._baseHide()) { - Flyout._cascadeManager.flyoutHiding(this); - } - }, - - _beforeEndHide: function Flyout_beforeEndHide() { - Flyout._cascadeManager.flyoutHidden(this); - }, - - _baseFlyoutShow: function Flyout_baseFlyoutShow(anchor, placement, alignment) { - if (this.disabled || this._disposed) { - // Don't do anything. - return; - } - - // Pick up defaults - if (!anchor) { - anchor = this._anchor; - } - if (!placement) { - placement = this._placement; - } - if (!alignment) { - alignment = this._alignment; - } - - // Dereference the anchor if necessary - if (typeof anchor === "string") { - anchor = _Global.document.getElementById(anchor); - } else if (anchor && anchor.element) { - anchor = anchor.element; - } - - // We expect an anchor - if (!anchor) { - // If we have _nextLeft, etc., then we were continuing an old animation, so that's OK - if (!this._reuseCurrent) { - throw new _ErrorFromName("WinJS.UI.Flyout.NoAnchor", strings.noAnchor); - } - // Last call was incomplete, so reuse the previous _current values. - this._reuseCurrent = null; - } else { - // Remember the anchor so that if we lose focus we can go back - this._currentAnchor = anchor; - // Remember current values - this._currentPlacement = placement; - this._currentAlignment = alignment; - } - - // If we're animating (eg baseShow is going to fail), or the cascadeManager is in the middle of a updating the cascade, - // then don't mess up our current state. - if (this._element.winAnimating) { - this._reuseCurrent = true; - // Queue us up to wait for the current animation to finish. - // _checkDoNext() is always scheduled after the current animation completes. - this._doNext = "show"; - } else if (Flyout._cascadeManager.reentrancyLock) { - this._reuseCurrent = true; - // Queue us up to wait for the current animation to finish. - // Schedule a call to _checkDoNext() for when the cascadeManager unlocks. - this._doNext = "show"; - var that = this; - Flyout._cascadeManager.unlocked.then(function () { that._checkDoNext(); }); - } else { - // We call our base _baseShow to handle the actual animation - if (this._baseShow()) { - // (_baseShow shouldn't ever fail because we tested winAnimating above). - if (!_ElementUtilities.hasClass(this.element, "win-menu")) { - // Verify that the firstDiv is in the correct location. - // Move it to the correct location or add it if not. - var _elms = this._element.getElementsByTagName("*"); - var firstDiv = this.element.querySelectorAll(".win-first"); - if (this.element.children.length && !_ElementUtilities.hasClass(this.element.children[0], _Constants.firstDivClass)) { - if (firstDiv && firstDiv.length > 0) { - firstDiv.item(0).parentNode.removeChild(firstDiv.item(0)); - } - - firstDiv = this._addFirstDiv(); - } - firstDiv.tabIndex = _ElementUtilities._getLowestTabIndexInList(_elms); - - // Verify that the finalDiv is in the correct location. - // Move it to the correct location or add it if not. - var finalDiv = this.element.querySelectorAll(".win-final"); - if (!_ElementUtilities.hasClass(this.element.children[this.element.children.length - 1], _Constants.finalDivClass)) { - if (finalDiv && finalDiv.length > 0) { - finalDiv.item(0).parentNode.removeChild(finalDiv.item(0)); - } - - finalDiv = this._addFinalDiv(); - } - finalDiv.tabIndex = _ElementUtilities._getHighestTabIndexInList(_elms); - } - - Flyout._cascadeManager.appendFlyout(this); - } - } - }, - - _lightDismiss: function Flyout_lightDismiss() { - Flyout._cascadeManager.collapseAll(); - }, - - // Find our new flyout position. - _findPosition: function Flyout_findPosition() { - this._adjustedHeight = 0; - this._nextTop = 0; - this._nextLeft = 0; - this._keyboardMovedUs = false; - this._doesScroll = false; - - // Make sure menu commands display correctly - if (this._checkMenuCommands) { - this._checkMenuCommands(); - } - - // Remove old height restrictions and scrolling. - this._clearAdjustedStyles(); - - this._setAlignment(this._currentAlignment); - - // Set up the new position, and prep the offset for showPopup. - this._getTopLeft(); - - // Adjust position - if (this._nextTop < 0) { - // Overran bottom, attach to bottom. - this._element.style.bottom = _Overlay._Overlay._keyboardInfo._visibleDocBottomOffset + "px"; - this._element.style.top = "auto"; - } else { - // Normal, set top - this._element.style.top = this._nextTop + "px"; - this._element.style.bottom = "auto"; - } - if (this._nextLeft < 0) { - // Overran right, attach to right - this._element.style.right = "0px"; - this._element.style.left = "auto"; - } else { - // Normal, set left - this._element.style.left = this._nextLeft + "px"; - this._element.style.right = "auto"; - } - - // Adjust height/scrollbar - if (this._doesScroll) { - _ElementUtilities.addClass(this._element, _Constants.scrollsClass); - this._lastMaxHeight = this._element.style.maxHeight; - this._element.style.maxHeight = this._adjustedHeight + "px"; - } - - // May need to adjust if the IHM is showing. - if (_Overlay._Overlay._keyboardInfo._visible) { - // Use keyboard logic - this._checkKeyboardFit(); - - if (this._keyboardMovedUs) { - this._adjustForKeyboard(); - } - } - }, - - // This determines our positioning. We have 8 modes, the 1st four are explicit, the last 4 are automatic: - // * top - position explicitly on the top of the anchor, shrinking and adding scrollbar as needed. - // * bottom - position explicitly below the anchor, shrinking and adding scrollbar as needed. - // * left - position left of the anchor, shrinking and adding a vertical scrollbar as needed. - // * right - position right of the anchor, shrinking and adding a vertical scroolbar as needed. - // * auto - Automatic placement. - // * autohorizontal - Automatic placement (only left or right). - // * autovertical - Automatic placement (only top or bottom). - // * _cascasde - Private placement used by MenuCommand._activateFlyoutCommand - // Auto tests the height of the anchor and the flyout. For consistency in orientation, we imagine - // that the anchor is placed in the vertical center of the display. If the flyout would fit above - // that centered anchor, then we will place the flyout vertically in relation to the anchor, otherwise - // placement will be horizontal. - // Vertical auto or autovertical placement will be positioned on top of the anchor if room, otherwise below the anchor. - // - this is because touch users would be more likely to obscure flyouts below the anchor. - // Horizontal auto or autohorizontal placement will be positioned to the left of the anchor if room, otherwise to the right. - // - this is because right handed users would be more likely to obscure a flyout on the right of the anchor. - // All three auto placements will add a vertical scrollbar if necessary. - // - _getTopLeft: function Flyout_getTopLeft() { - - var that = this; - - function configureVerticalWithScroll(anchor) { - // Won't fit top or bottom. Pick the one with the most space and add a scrollbar. - if (topHasMoreRoom(anchor)) { - // Top - that._adjustedHeight = spaceAbove(anchor) - that._verticalMarginBorderPadding; - that._nextTop = _Overlay._Overlay._keyboardInfo._visibleDocTop; - that._nextAnimOffset = AnimationOffsets.top; - } else { - // Bottom - that._adjustedHeight = spaceBelow(anchor) - that._verticalMarginBorderPadding; - that._nextTop = _Constants.pinToBottomEdge; - that._nextAnimOffset = AnimationOffsets.bottom; - } - that._doesScroll = true; - } - - // If the anchor is centered vertically, would the flyout fit above it? - function fitsVerticallyWithCenteredAnchor(anchor, flyout) { - // Returns true if the flyout would always fit at least top - // or bottom of its anchor, regardless of the position of the anchor, - // as long as the anchor never changed its height, nor did the height of - // the visualViewport change. - return ((_Overlay._Overlay._keyboardInfo._visibleDocHeight - anchor.height) / 2) >= flyout.totalHeight; - } - - function spaceAbove(anchor) { - return anchor.top - _Overlay._Overlay._keyboardInfo._visibleDocTop; - } - - function spaceBelow(anchor) { - return _Overlay._Overlay._keyboardInfo._visibleDocBottom - anchor.bottom; - } - - function topHasMoreRoom(anchor) { - return spaceAbove(anchor) > spaceBelow(anchor); - } - - // See if we can fit in various places, fitting in the main view, - // ignoring viewport changes, like for the IHM. - function fitTop(bottomConstraint, flyout) { - that._nextTop = bottomConstraint - flyout.totalHeight; - that._nextAnimOffset = AnimationOffsets.top; - return (that._nextTop >= _Overlay._Overlay._keyboardInfo._visibleDocTop && - that._nextTop + flyout.totalHeight <= _Overlay._Overlay._keyboardInfo._visibleDocBottom); - } - - function fitBottom(topConstraint, flyout) { - that._nextTop = topConstraint; - that._nextAnimOffset = AnimationOffsets.bottom; - return (that._nextTop >= _Overlay._Overlay._keyboardInfo._visibleDocTop && - that._nextTop + flyout.totalHeight <= _Overlay._Overlay._keyboardInfo._visibleDocBottom); - } - - function fitLeft(leftConstraint, flyout) { - that._nextLeft = leftConstraint - flyout.totalWidth; - that._nextAnimOffset = AnimationOffsets.left; - return (that._nextLeft >= 0 && that._nextLeft + flyout.totalWidth <= _Overlay._Overlay._keyboardInfo._visualViewportWidth); - } - - function fitRight(rightConstraint, flyout) { - that._nextLeft = rightConstraint; - that._nextAnimOffset = AnimationOffsets.right; - return (that._nextLeft >= 0 && that._nextLeft + flyout.totalWidth <= _Overlay._Overlay._keyboardInfo._visualViewportWidth); - } - - function centerVertically(anchor, flyout) { - that._nextTop = anchor.top + anchor.height / 2 - flyout.totalHeight / 2; - if (that._nextTop < _Overlay._Overlay._keyboardInfo._visibleDocTop) { - that._nextTop = _Overlay._Overlay._keyboardInfo._visibleDocTop; - } else if (that._nextTop + flyout.totalHeight >= _Overlay._Overlay._keyboardInfo._visibleDocBottom) { - // Flag to pin to bottom edge of visual document. - that._nextTop = _Constants.pinToBottomEdge; - } - } - - function alignHorizontally(anchor, flyout, alignment) { - if (alignment === "center") { - that._nextLeft = anchor.left + anchor.width / 2 - flyout.totalWidth / 2; - } else if (alignment === "left") { - that._nextLeft = anchor.left; - } else if (alignment === "right") { - that._nextLeft = anchor.right - flyout.totalWidth; - } else { - throw new _ErrorFromName("WinJS.UI.Flyout.BadAlignment", strings.badAlignment); - } - if (that._nextLeft < 0) { - that._nextLeft = 0; - } else if (that._nextLeft + flyout.totalWidth >= _Overlay._Overlay._keyboardInfo._visualViewportWidth) { - // Flag to pin to right edge of visible document. - that._nextLeft = _Constants.pinToRightEdge; - } - } - - var anchorRawRectangle, - flyout = {}, - anchor = {}; - - try { - anchorRawRectangle = this._currentAnchor.getBoundingClientRect(); - } - catch (e) { - throw new _ErrorFromName("WinJS.UI.Flyout.NoAnchor", strings.noAnchor); - } - - // Adjust for the anchor's margins. - anchor.top = anchorRawRectangle.top; - anchor.bottom = anchorRawRectangle.bottom; - anchor.left = anchorRawRectangle.left; - anchor.right = anchorRawRectangle.right; - anchor.height = anchor.bottom - anchor.top; - anchor.width = anchor.right - anchor.left; - - // Get our flyout and margins, note that getDimension calls - // window.getComputedStyle, which ensures layout is updated. - flyout.marginTop = getDimension(this._element, "marginTop"); - flyout.marginBottom = getDimension(this._element, "marginBottom"); - flyout.marginLeft = getDimension(this._element, "marginLeft"); - flyout.marginRight = getDimension(this._element, "marginRight"); - flyout.totalWidth = _ElementUtilities.getTotalWidth(this._element); - flyout.totalHeight = _ElementUtilities.getTotalHeight(this._element); - flyout.contentWidth = _ElementUtilities.getContentWidth(this._element); - flyout.contentHeight = _ElementUtilities.getContentHeight(this._element); - this._verticalMarginBorderPadding = (flyout.totalHeight - flyout.contentHeight); - this._adjustedHeight = flyout.contentHeight; - - // Check fit for requested this._currentPlacement, doing fallback if necessary - switch (this._currentPlacement) { - case "top": - if (!fitTop(anchor.top, flyout)) { - // Didn't fit, needs scrollbar - this._nextTop = _Overlay._Overlay._keyboardInfo._visibleDocTop; - this._doesScroll = true; - this._adjustedHeight = spaceAbove(anchor) - this._verticalMarginBorderPadding; - } - alignHorizontally(anchor, flyout, this._currentAlignment); - break; - case "bottom": - if (!fitBottom(anchor.bottom, flyout)) { - // Didn't fit, needs scrollbar - this._nextTop = _Constants.pinToBottomEdge; - this._doesScroll = true; - this._adjustedHeight = spaceBelow(anchor) - this._verticalMarginBorderPadding; - } - alignHorizontally(anchor, flyout, this._currentAlignment); - break; - case "left": - if (!fitLeft(anchor.left, flyout)) { - // Didn't fit, just shove it to edge - this._nextLeft = 0; - } - centerVertically(anchor, flyout); - break; - case "right": - if (!fitRight(anchor.right, flyout)) { - // Didn't fit, just shove it to edge - this._nextLeft = _Constants.pinToRightEdge; - } - centerVertically(anchor, flyout); - break; - case "autovertical": - if (!fitTop(anchor.top, flyout)) { - // Didn't fit above (preferred), so go below. - if (!fitBottom(anchor.bottom, flyout)) { - // Didn't fit, needs scrollbar - configureVerticalWithScroll(anchor); - } - } - alignHorizontally(anchor, flyout, this._currentAlignment); - break; - case "autohorizontal": - if (!fitLeft(anchor.left, flyout)) { - // Didn't fit left (preferred), so go right. - if (!fitRight(anchor.right, flyout)) { - // Didn't fit,just shove it to edge - this._nextLeft = _Constants.pinToRightEdge; - } - } - centerVertically(anchor, flyout); - break; - case "auto": - // Auto, if the anchor was in the vertical center of the display would we fit above it? - if (fitsVerticallyWithCenteredAnchor(anchor, flyout)) { - // It will fit above or below the anchor - if (!fitTop(anchor.top, flyout)) { - // Didn't fit above (preferred), so go below. - fitBottom(anchor.bottom, flyout); - } - alignHorizontally(anchor, flyout, this._currentAlignment); - } else { - // Won't fit above or below, try a side - if (!fitLeft(anchor.left, flyout) && - !fitRight(anchor.right, flyout)) { - // Didn't fit left or right either - configureVerticalWithScroll(anchor); - alignHorizontally(anchor, flyout, this._currentAlignment); - } else { - centerVertically(anchor, flyout); - } - } - break; - case "_cascade": - // Align vertically - // PREFERRED: When there is enough room to align a subMenu to either the top or the bottom of its - // anchor element, the subMenu prefers to be top aligned. - // FALLBACK: When there is enough room to bottom align a subMenu but not enough room to top align it, - // then the subMenu will align to the bottom of its anchor element. - // LASTRESORT: When there is not enough room to top align or bottom align the subMenu to its anchor, - // then the subMenu will be center aligned to it's anchor's vertical midpoint. - if (!fitBottom(anchor.top - flyout.marginTop, flyout) && !fitTop(anchor.bottom + flyout.marginBottom, flyout)) { - centerVertically(anchor, flyout); - } - // Determine horizontal direction - // PREFERRED: When there is enough room to fit a subMenu on either side of the anchor, - // the subMenu prefers to go on the right hand side. - // FALLBACK: When there is only enough room to fit a subMenu on the left side of the anchor, - // the subMenu is placed to the left of the parent menu. - // LASTRESORT: When there is not enough room to fit a subMenu on either side of the anchor, - // the subMenu is pinned to the right edge of the window. - var rtl = _Global.getComputedStyle(this._element).direction === "rtl"; - - // Cascading Menus should overlap their ancestor menu by 4 pixels and we have a unit test to - // verify that behavior. Because we don't have access to the ancestor flyout we need to specify - // the overlap in terms of our anchor element. There is a 1px border around the menu that - // contains our anchor we need to overlap our anchor by 3px to ensure that we overlap the containing - // Menu by 4px. - var pixelsToOverlapAnchor = 3; - - var beginRight = anchor.right - flyout.marginLeft - pixelsToOverlapAnchor; - var beginLeft = anchor.left + flyout.marginRight + pixelsToOverlapAnchor; - - if (rtl) { - if (!fitLeft(beginLeft, flyout) && !fitRight(beginRight, flyout)) { - // Doesn't fit on either side, pin to the left edge. - that._nextLeft = 0; - that._nextAnimOffset = AnimationOffsets.left; - } - } else { - if (!fitRight(beginRight, flyout) && !fitLeft(beginLeft, flyout)) { - // Doesn't fit on either side, pin to the right edge of the visible document. - that._nextLeft = _Constants.pinToRightEdge; - that._nextAnimOffset = AnimationOffsets.right; - } - } - - break; - default: - // Not a legal this._currentPlacement value - throw new _ErrorFromName("WinJS.UI.Flyout.BadPlacement", strings.badPlacement); - } - }, - - _clearAdjustedStyles: function Flyout_clearAdjustedStyles() { - // Move to 0,0 in case it is off screen, so that it lays out at a reasonable size - this._element.style.top = "0px"; - this._element.style.bottom = "auto"; - this._element.style.left = "0px"; - this._element.style.right = "auto"; - - // Clear height restrictons and scrollbar class - _ElementUtilities.removeClass(this._element, _Constants.scrollsClass); - if (this._lastMaxHeight !== null) { - this._element.style.maxHeight = this._lastMaxHeight; - this._lastMaxHeight = null; - } - - // Clear Alignment - _ElementUtilities.removeClass(this._element, "win-rightalign"); - _ElementUtilities.removeClass(this._element, "win-leftalign"); - }, - - _setAlignment: function Flyout_setAlignment(alignment) { - // Alignment - switch (alignment) { - case "left": - _ElementUtilities.addClass(this._element, "win-leftalign"); - break; - case "right": - _ElementUtilities.addClass(this._element, "win-rightalign"); - break; - case "center": - case "none": - break; - } - }, - - _showingKeyboard: function Flyout_showingKeyboard(event) { - if (this.hidden) { - return; - } - - // The only way that we can be showing a keyboard when a flyout is up is because the input was - // in the flyout itself, in which case we'll be moving ourselves. There is no practical way - // for the application to override this as the focused element is in our flyout. - event.ensuredFocusedElementInView = true; - - // See if the keyboard is going to force us to move - this._checkKeyboardFit(); - - if (this._keyboardMovedUs) { - // Pop out immediately, then move to new spot - this._element.style.opacity = 0; - var that = this; - _Global.setTimeout(function () { that._adjustForKeyboard(); that._baseAnimateIn(); }, _Overlay._Overlay._keyboardInfo._animationShowLength); - } - }, - - _resize: function Flyout_resize() { - // If hidden and not busy animating, then nothing to do - if (!this.hidden || this._animating) { - - // This should only happen if the IHM is dismissing, - // the only other way is for viewstate changes, which - // would dismiss any flyout. - if (this._needToHandleHidingKeyboard) { - // Hiding keyboard, update our position, giving the anchor a chance to update first. - var that = this; - _BaseUtils._setImmediate(function () { - if (!that.hidden || that._animating) { - that._findPosition(); - } - }); - this._needToHandleHidingKeyboard = false; - } - } - }, - - // If you were not pinned to the bottom, you might have to be now. - _checkKeyboardFit: function Flyout_checkKeyboardFit() { - // Special Flyout positioning rules to determine if the Flyout needs to adjust its - // position because of the IHM. If the Flyout needs to adjust for the IHM, it will reposition - // itself to be pinned to either the top or bottom edge of the visual viewport. - // - Too Tall, above top, or below bottom. - - var keyboardMovedUs = false; - var viewportHeight = _Overlay._Overlay._keyboardInfo._visibleDocHeight; - var adjustedMarginBoxHeight = this._adjustedHeight + this._verticalMarginBorderPadding; - if (adjustedMarginBoxHeight > viewportHeight) { - // The Flyout is now too tall to fit in the viewport, pin to top and adjust height. - keyboardMovedUs = true; - this._nextTop = _Constants.pinToBottomEdge; - this._adjustedHeight = viewportHeight - this._verticalMarginBorderPadding; - this._doesScroll = true; - } else if (this._nextTop >= 0 && - this._nextTop + adjustedMarginBoxHeight > _Overlay._Overlay._keyboardInfo._visibleDocBottom) { - // Flyout clips the bottom of the viewport. Pin to bottom. - this._nextTop = _Constants.pinToBottomEdge; - keyboardMovedUs = true; - } else if (this._nextTop === _Constants.pinToBottomEdge) { - // We were already pinned to the bottom, so our position on screen will change - keyboardMovedUs = true; - } - - // Signals use of basic fadein animation - this._keyboardMovedUs = keyboardMovedUs; - }, - - _adjustForKeyboard: function Flyout_adjustForKeyboard() { - // Keyboard moved us, update our metrics as needed - if (this._doesScroll) { - // Add scrollbar if we didn't already have scrollsClass - if (!this._lastMaxHeight) { - _ElementUtilities.addClass(this._element, _Constants.scrollsClass); - this._lastMaxHeight = this._element.style.maxHeight; - } - // Adjust height - this._element.style.maxHeight = this._adjustedHeight + "px"; - } - - // Update top/bottom - this._checkScrollPosition(true); - }, - - _hidingKeyboard: function Flyout_hidingKeyboard() { - // If we aren't visible and not animating, or haven't been repositioned, then nothing to do - // We don't know if the keyboard moved the anchor, so _keyboardMovedUs doesn't help here - if (!this.hidden || this._animating) { - - // Snap to the final position - // We'll either just reveal the current space or resize the window - if (_Overlay._Overlay._keyboardInfo._isResized) { - // Flag resize that we'll need an updated position - this._needToHandleHidingKeyboard = true; - } else { - // Not resized, update our final position, giving the anchor a chance to update first. - var that = this; - _BaseUtils._setImmediate(function () { - if (!that.hidden || that._animating) { - that._findPosition(); - } - }); - } - } - }, - - _checkScrollPosition: function Flyout_checkScrollPosition(showing) { - if (this.hidden && !showing) { - return; - } - - // May need to adjust top by viewport offset - if (this._nextTop < 0) { - // Need to attach to bottom - this._element.style.bottom = _Overlay._Overlay._keyboardInfo._visibleDocBottomOffset + "px"; - this._element.style.top = "auto"; - } else { - // Normal, attach to top - this._element.style.top = this._nextTop + "px"; - this._element.style.bottom = "auto"; - } - }, - - // AppBar flyout animations - _flyoutAnimateIn: function Flyout_flyoutAnimateIn() { - if (this._keyboardMovedUs) { - return this._baseAnimateIn(); - } else { - this._element.style.opacity = 1; - this._element.style.visibility = "visible"; - return Animations.showPopup(this._element, this._nextAnimOffset); - } - }, - - _flyoutAnimateOut: function Flyout_flyoutAnimateOut() { - if (this._keyboardMovedUs) { - return this._baseAnimateOut(); - } else { - this._element.style.opacity = 0; - return Animations.hidePopup(this._element, this._nextAnimOffset); - } - }, - - // Hide all other flyouts besides this one - _hideAllOtherFlyouts: function Flyout_hideAllOtherFlyouts(thisFlyout) { - var flyouts = _Global.document.querySelectorAll("." + _Constants.flyoutClass); - for (var i = 0; i < flyouts.length; i++) { - var flyoutControl = flyouts[i].winControl; - if (flyoutControl && !flyoutControl.hidden && (flyoutControl !== thisFlyout)) { - flyoutControl.hide(); - } - } - }, - - _handleKeyDown: function Flyout_handleKeyDown(event) { - if ((event.keyCode === Key.space || event.keyCode === Key.enter) - && (this === _Global.document.activeElement)) { - event.preventDefault(); - event.stopPropagation(); - this.winControl.hide(); - } else if (event.shiftKey && event.keyCode === Key.tab - && this === _Global.document.activeElement - && !event.altKey && !event.ctrlKey && !event.metaKey) { - event.preventDefault(); - event.stopPropagation(); - this.winControl._focusOnLastFocusableElementOrThis(); - } - }, - - _handleFocusIn: function Flyout_handleFocusIn(event) { - if (!this.element.contains(event.relatedTarget)) { - Flyout._cascadeManager.handleFocusIntoFlyout(event); - } - // Else focus is only moving between elements in the flyout. - // Doesn't need to be handled by cascadeManager. - }, - - // Create and add a new first div as the first child - _addFirstDiv: function Flyout_addFirstDiv() { - var firstDiv = _Global.document.createElement("div"); - firstDiv.className = _Constants.firstDivClass; - firstDiv.style.display = "inline"; - firstDiv.setAttribute("role", "menuitem"); - firstDiv.setAttribute("aria-hidden", "true"); - - // add to beginning - if (this._element.children[0]) { - this._element.insertBefore(firstDiv, this._element.children[0]); - } else { - this._element.appendChild(firstDiv); - } - - var that = this; - _ElementUtilities._addEventListener(firstDiv, "focusin", function () { that._focusOnLastFocusableElementOrThis(); }, false); - - return firstDiv; - }, - - // Create and add a new final div as the last child - _addFinalDiv: function Flyout_addFinalDiv() { - var finalDiv = _Global.document.createElement("div"); - finalDiv.className = _Constants.finalDivClass; - finalDiv.style.display = "inline"; - finalDiv.setAttribute("role", "menuitem"); - finalDiv.setAttribute("aria-hidden", "true"); - - this._element.appendChild(finalDiv); - var that = this; - _ElementUtilities._addEventListener(finalDiv, "focusin", function () { that._focusOnFirstFocusableElementOrThis(); }, false); - - return finalDiv; - }, - - _writeProfilerMark: function Flyout_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI.Flyout:" + this._id + ":" + text); - } - }, - { - _cascadeManager: new _CascadeManager(), - }); - return Flyout; - }) - }); - -}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/CommandingSurface/_Constants',["require", "exports"], function (require, exports) { - // CommandingSurface class names - exports.ClassNames = { - controlCssClass: "win-commandingsurface", - disposableCssClass: "win-disposable", - actionAreaCssClass: "win-commandingsurface-actionarea", - actionAreaContainerCssClass: "win-commandingsurface-actionareacontainer", - overflowButtonCssClass: "win-commandingsurface-overflowbutton", - spacerCssClass: "win-commandingsurface-spacer", - ellipsisCssClass: "win-commandingsurface-ellipsis", - overflowAreaCssClass: "win-commandingsurface-overflowarea", - overflowAreaContainerCssClass: "win-commandingsurface-overflowareacontainer", - contentFlyoutCssClass: "win-commandingsurface-contentflyout", - emptyCommandingSurfaceCssClass: "win-commandingsurface-empty", - menuCssClass: "win-menu", - menuContainsToggleCommandClass: "win-menu-containstogglecommand", - openedClass: "win-commandingsurface-opened", - closingClass: "win-commandingsurface-closing", - closedClass: "win-commandingsurface-closed", - noneClass: "win-commandingsurface-closeddisplaynone", - minimalClass: "win-commandingsurface-closeddisplayminimal", - compactClass: "win-commandingsurface-closeddisplaycompact", - fullClass: "win-commandingsurface-closeddisplayfull", - overflowTopClass: "win-commandingsurface-overflowtop", - overflowBottomClass: "win-commandingsurface-overflowbottom", - }; - exports.EventNames = { - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose", - commandPropertyMutated: "_commandpropertymutated", - }; - exports.actionAreaCommandWidth = 68; - exports.actionAreaSeparatorWidth = 34; - exports.actionAreaOverflowButtonWidth = 32; - exports.overflowCommandHeight = 44; - exports.overflowSeparatorHeight = 12; - exports.controlMinWidth = exports.actionAreaOverflowButtonWidth; - exports.overflowAreaMaxWidth = 480; - exports.heightOfMinimal = 24; - exports.heightOfCompact = 48; - exports.contentMenuCommandDefaultLabel = "Custom content"; - exports.defaultClosedDisplayMode = "compact"; - exports.defaultOpened = false; - exports.defaultOverflowDirection = "bottom"; - // Constants for commands - exports.typeSeparator = "separator"; - exports.typeContent = "content"; - exports.typeButton = "button"; - exports.typeToggle = "toggle"; - exports.typeFlyout = "flyout"; - exports.commandSelector = ".win-command"; - exports.primaryCommandSection = "primary"; - exports.secondaryCommandSection = "secondary"; -}); - -define('WinJS/Controls/ToolBar/_Constants',["require", "exports", "../CommandingSurface/_Constants"], function (require, exports, _CommandingSurfaceConstants) { - // toolbar class names - exports.ClassNames = { - controlCssClass: "win-toolbar", - disposableCssClass: "win-disposable", - actionAreaCssClass: "win-toolbar-actionarea", - overflowButtonCssClass: "win-toolbar-overflowbutton", - spacerCssClass: "win-toolbar-spacer", - ellipsisCssClass: "win-toolbar-ellipsis", - overflowAreaCssClass: "win-toolbar-overflowarea", - contentFlyoutCssClass: "win-toolbar-contentflyout", - emptytoolbarCssClass: "win-toolbar-empty", - menuCssClass: "win-menu", - menuContainsToggleCommandClass: "win-menu-containstogglecommand", - openedClass: "win-toolbar-opened", - closedClass: "win-toolbar-closed", - compactClass: "win-toolbar-closeddisplaycompact", - fullClass: "win-toolbar-closeddisplayfull", - overflowTopClass: "win-toolbar-overflowtop", - overflowBottomClass: "win-toolbar-overflowbottom", - placeHolderCssClass: "win-toolbar-placeholder", - }; - exports.EventNames = { - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose" - }; - exports.OverflowDirection = { - top: "top", - bottom: "bottom", - }; - exports.overflowAreaMaxWidth = _CommandingSurfaceConstants.overflowAreaMaxWidth; - exports.controlMinWidth = _CommandingSurfaceConstants.controlMinWidth; - exports.defaultClosedDisplayMode = "compact"; - exports.defaultOpened = false; - // Constants for commands - exports.typeSeparator = "separator"; - exports.typeContent = "content"; - exports.typeButton = "button"; - exports.typeToggle = "toggle"; - exports.typeFlyout = "flyout"; - exports.commandSelector = ".win-command"; - exports.primaryCommandSection = "primary"; - exports.secondaryCommandSection = "secondary"; -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// Glyph Enumeration -/// Segoe -define('WinJS/Controls/AppBar/_Icon',[ - 'exports', - '../../Core/_Base', - '../../Core/_Resources' - ], function appBarIconInit(exports, _Base, _Resources) { - "use strict"; - - var glyphs = ["previous", - "next", - "play", - "pause", - "edit", - "save", - "clear", - "delete", - "remove", - "add", - "cancel", - "accept", - "more", - "redo", - "undo", - "home", - "up", - "forward", - "right", - "back", - "left", - "favorite", - "camera", - "settings", - "video", - "sync", - "download", - "mail", - "find", - "help", - "upload", - "emoji", - "twopage", - "leavechat", - "mailforward", - "clock", - "send", - "crop", - "rotatecamera", - "people", - "closepane", - "openpane", - "world", - "flag", - "previewlink", - "globe", - "trim", - "attachcamera", - "zoomin", - "bookmarks", - "document", - "protecteddocument", - "page", - "bullets", - "comment", - "mail2", - "contactinfo", - "hangup", - "viewall", - "mappin", - "phone", - "videochat", - "switch", - "contact", - "rename", - "pin", - "musicinfo", - "go", - "keyboard", - "dockleft", - "dockright", - "dockbottom", - "remote", - "refresh", - "rotate", - "shuffle", - "list", - "shop", - "selectall", - "orientation", - "import", - "importall", - "browsephotos", - "webcam", - "pictures", - "savelocal", - "caption", - "stop", - "showresults", - "volume", - "repair", - "message", - "page2", - "calendarday", - "calendarweek", - "calendar", - "characters", - "mailreplyall", - "read", - "link", - "accounts", - "showbcc", - "hidebcc", - "cut", - "attach", - "paste", - "filter", - "copy", - "emoji2", - "important", - "mailreply", - "slideshow", - "sort", - "manage", - "allapps", - "disconnectdrive", - "mapdrive", - "newwindow", - "openwith", - "contactpresence", - "priority", - "uploadskydrive", - "gototoday", - "font", - "fontcolor", - "contact2", - "folder", - "audio", - "placeholder", - "view", - "setlockscreen", - "settile", - "cc", - "stopslideshow", - "permissions", - "highlight", - "disableupdates", - "unfavorite", - "unpin", - "openlocal", - "mute", - "italic", - "underline", - "bold", - "movetofolder", - "likedislike", - "dislike", - "like", - "alignright", - "aligncenter", - "alignleft", - "zoom", - "zoomout", - "openfile", - "otheruser", - "admin", - "street", - "map", - "clearselection", - "fontdecrease", - "fontincrease", - "fontsize", - "cellphone", - "reshare", - "tag", - "repeatone", - "repeatall", - "outlinestar", - "solidstar", - "calculator", - "directions", - "target", - "library", - "phonebook", - "memo", - "microphone", - "postupdate", - "backtowindow", - "fullscreen", - "newfolder", - "calendarreply", - "unsyncfolder", - "reporthacked", - "syncfolder", - "blockcontact", - "switchapps", - "addfriend", - "touchpointer", - "gotostart", - "zerobars", - "onebar", - "twobars", - "threebars", - "fourbars", - "scan", - "preview", - "hamburger"]; - - // Provide properties to grab resources for each of the icons - /// - /// The AppBarIcon enumeration provides a set of glyphs for use with the AppBarCommand icon property. - /// - var icons = glyphs.reduce(function (fixedIcons, item) { - fixedIcons[item] = { get: function () { return _Resources._getWinJSString("ui/appBarIcons/" + item).value; } }; - return fixedIcons; - }, {}); - - _Base.Namespace._moduleDefine(exports, "WinJS.UI.AppBarIcon", icons); -}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// AppBarCommand -/// appbar,appbars,Flyout,Flyouts,onclick,Statics -define('WinJS/Controls/AppBar/_Command',[ - 'exports', - '../../Core/_Global', - '../../Core/_WinRT', - '../../Core/_Base', - "../../Core/_BaseUtils", - '../../Core/_ErrorFromName', - "../../Core/_Events", - '../../Core/_Resources', - '../../Utilities/_Control', - '../../Utilities/_Dispose', - '../../Utilities/_ElementUtilities', - '../Flyout/_Overlay', - '../Tooltip', - '../_LegacyAppBar/_Constants', - './_Icon' -], function appBarCommandInit(exports, _Global, _WinRT, _Base, _BaseUtils, _ErrorFromName, _Events, _Resources, _Control, _Dispose, _ElementUtilities, _Overlay, Tooltip, _Constants, _Icon) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// Represents a command to display in an AppBar. - /// - /// - /// - /// - /// ]]> - /// Raised after the hidden property has been programmatically changed. - /// The AppBarCommand control itself. - /// The AppBarCommand's icon box. - /// The AppBarCommand's icon's image formatting. - /// The AppBarCommand's label - /// - /// - AppBarCommand: _Base.Namespace._lazy(function () { - - function _handleClick(event) { - /*jshint validthis: true */ - var command = this.winControl; - if (command) { - if (command._type === _Constants.typeToggle) { - command.selected = !command.selected; - } else if (command._type === _Constants.typeFlyout && command._flyout) { - var flyout = command._flyout; - // Flyout may not have processAll'd, so this may be a DOM object - if (typeof flyout === "string") { - flyout = _Global.document.getElementById(flyout); - } - if (!flyout.show) { - flyout = flyout.winControl; - } - if (flyout && flyout.show) { - flyout.show(this, "autovertical"); - } - } - if (command.onclick) { - command.onclick(event); - } - } - } - - // Used by AppBarCommands to notify listeners that a property has changed. - var PropertyMutations = _Base.Class.define(function PropertyMutations_ctor() { - this._observer = _BaseUtils._merge({}, _Events.eventMixin); - }, { - bind: function (callback) { - this._observer.addEventListener(_Constants.commandPropertyMutated, callback); - }, - unbind: function (callback) { - this._observer.removeEventListener(_Constants.commandPropertyMutated, callback); - }, - dispatchEvent: function (type, detail) { - this._observer.dispatchEvent(type, detail); - }, - }); - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/appBarCommandAriaLabel").value; }, - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get badClick() { return "Invalid argument: The onclick property for an {0} must be a function"; }, - get badDivElement() { return "Invalid argument: For a content command, the element must be null or a div element"; }, - get badHrElement() { return "Invalid argument: For a separator, the element must be null or an hr element"; }, - get badButtonElement() { return "Invalid argument: For a button, toggle, or flyout command, the element must be null or a button element"; }, - get badPriority() { return "Invalid argument: the priority of an {0} must be a non-negative integer"; } - }; - - var AppBarCommand = _Base.Class.define(function AppBarCommand_ctor(element, options) { - /// - /// - /// Creates a new AppBarCommand control. - /// - /// - /// The DOM element that will host the control. AppBarCommand will create one if null. - /// - /// - /// The set of properties and values to apply to the new AppBarCommand. - /// - /// - /// The new AppBarCommand control. - /// - /// - - // Check to make sure we weren't duplicated - if (element && element.winControl) { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.DuplicateConstruction", strings.duplicateConstruction); - } - - this._disposed = false; - - // Don't blow up if they didn't pass options - if (!options) { - options = {}; - } - - // Need a type before we can create our element - if (!options.type) { - this._type = _Constants.typeButton; - } - - options.section = options.section || _Constants.sectionPrimary; - - // Go ahead and create it, separator and content types look different than buttons - // Don't forget to use passed in element if one was provided. - this._element = element; - - if (options.type === _Constants.typeContent) { - this._createContent(); - } else if (options.type === _Constants.typeSeparator) { - this._createSeparator(); - } else { - // This will also set the icon & label - this._createButton(); - } - _ElementUtilities.addClass(this._element, "win-disposable"); - - // Remember ourselves - this._element.winControl = this; - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.appBarCommandClass); - - if (options.onclick) { - this.onclick = options.onclick; - } - // We want to handle some clicks - options.onclick = _handleClick; - - _Control.setOptions(this, options); - - if (this._type === _Constants.typeToggle && !options.selected) { - this.selected = false; - } - - // Set up pointerdown handler and clean up ARIA if needed - if (this._type !== _Constants.typeSeparator) { - - // Make sure we have an ARIA role - var role = this._element.getAttribute("role"); - if (role === null || role === "" || role === undefined) { - if (this._type === _Constants.typeToggle) { - role = "menuitemcheckbox"; - } else if (this._type === _Constants.typeContent) { - role = "group"; - } else { - role = "menuitem"; - } - this._element.setAttribute("role", role); - if (this._type === _Constants.typeFlyout) { - this._element.setAttribute("aria-haspopup", true); - } - } - // Label should've been set by label, but if it was missed for some reason: - var label = this._element.getAttribute("aria-label"); - if (label === null || label === "" || label === undefined) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - } - - this._propertyMutations = new PropertyMutations(); - var that = this; - ObservablePropertyWhiteList.forEach(function (propertyName) { - makeObservable(that, propertyName); - }); - }, { - /// - /// Gets or sets the ID of the AppBarCommand. - /// - id: { - get: function () { - return this._element.id; - }, - - set: function (value) { - // we allow setting first time only. otherwise we ignore it. - if (value && !this._element.id) { - this._element.id = value; - } - } - }, - - /// - /// Gets or sets the type of the AppBarCommand. Possible values are "button", "toggle", "flyout", "content" or "separator". - /// - type: { - get: function () { - return this._type; - }, - set: function (value) { - // we allow setting first time only. otherwise we ignore it. - if (!this._type) { - if (value !== _Constants.typeContent && value !== _Constants.typeFlyout && value !== _Constants.typeToggle && value !== _Constants.typeSeparator) { - this._type = _Constants.typeButton; - } else { - this._type = value; - } - } - } - }, - - /// - /// Gets or sets the label of the AppBarCommand. - /// - label: { - get: function () { - return this._label; - }, - set: function (value) { - this._label = value; - if (this._labelSpan) { - this._labelSpan.textContent = this.label; - } - - // Ensure that we have a tooltip, by updating already-constructed tooltips. Separators won't have these: - if (!this.tooltip && this._tooltipControl) { - this._tooltip = this.label; - this._tooltipControl.innerHTML = this.label; - } - - // Update aria-label - this._element.setAttribute("aria-label", this.label); - - // Check if we need to suppress the tooltip - this._testIdenticalTooltip(); - } - }, - - /// - /// Gets or sets the icon of the AppBarCommand. - /// - icon: { - get: function () { - return this._icon; - }, - set: function (value) { - - this._icon = _Icon[value] || value; - - if (this._imageSpan) { - // If the icon's a single character, presume a glyph - if (this._icon && this._icon.length === 1) { - // Set the glyph - this._imageSpan.textContent = this._icon; - this._imageSpan.style.backgroundImage = ""; - this._imageSpan.style.msHighContrastAdjust = ""; - _ElementUtilities.addClass(this._imageSpan, "win-commandglyph"); - } else { - // Must be an image, set that - this._imageSpan.textContent = ""; - this._imageSpan.style.backgroundImage = this._icon; - this._imageSpan.style.msHighContrastAdjust = "none"; - _ElementUtilities.removeClass(this._imageSpan, "win-commandglyph"); - } - } - } - }, - - /// - /// Gets or sets the function to invoke when the command is clicked. - /// - onclick: { - get: function () { - return this._onclick; - }, - set: function (value) { - if (value && typeof value !== "function") { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.BadClick", _Resources._formatString(strings.badClick, "AppBarCommand")); - } - this._onclick = value; - } - }, - - /// - /// Gets or sets the priority of the command - /// - priority: { - get: function () { - return this._priority; - }, - set: function (value) { - if (value === undefined || (typeof value === "number" && value >= 0)) { - this._priority = value; - } else { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.BadPriority", _Resources._formatString(strings.badPriority, "AppBarCommand")); - } - - } - }, - - /// - /// For flyout-type AppBarCommands, this property returns the WinJS.UI.Flyout that this command invokes. - /// When setting this property, you may also use the String ID of the flyout to invoke, the DOM object - /// for the flyout, or the WinJS.UI.Flyout object itself. - /// If the value is set to the String ID of the flyout to invoke, or the DOM object for the flyout, but this - /// has not been processed yet, the getter will return the DOM object until it is processed, and - /// subsequently return a flyout. - /// - flyout: { - get: function () { - // Resolve it to the flyout - var flyout = this._flyout; - if (typeof flyout === "string") { - flyout = _Global.document.getElementById(flyout); - } - // If it doesn't have a .element, then we need to getControl on it - if (flyout && !flyout.element && flyout.winControl) { - flyout = flyout.winControl; - } - - return flyout; - }, - set: function (value) { - // Need to update aria-owns with the new ID. - var id = value; - if (id && typeof id !== "string") { - // Our controls have .element properties - if (id.element) { - id = id.element; - } - // Hope it's a DOM element, get ID from DOM element - if (id) { - if (id.id) { - id = id.id; - } else { - // No id, have to fake one - id.id = _ElementUtilities._uniqueID(id); - id = id.id; - } - } - } - if (typeof id === "string") { - this._element.setAttribute("aria-owns", id); - } - - // Remember it - this._flyout = value; - } - }, - - /// - /// Gets or sets the section that the AppBarCommand is in. Possible values are "secondary" and "primary". - /// - section: { - get: function () { - return this._section; - }, - set: function (value) { - // we allow settings section only one time - if (!this._section || _WinRT.Windows.ApplicationModel.DesignMode.designModeEnabled) { - this._setSection(value); - } - } - }, - - /// Gets or sets the tooltip text of the AppBarCommand. - tooltip: { - get: function () { - return this._tooltip; - }, - set: function (value) { - this._tooltip = value; - - // Update already-constructed tooltips. Separators and content commands won't have these: - if (this._tooltipControl) { - this._tooltipControl.innerHTML = this._tooltip; - } - - // Check if we need to suppress the tooltip - this._testIdenticalTooltip(); - } - }, - - /// Set or get the selected state of a toggle button. - selected: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return this._element.getAttribute("aria-checked") === "true"; - }, - set: function (value) { - this._element.setAttribute("aria-checked", value); - } - }, - - /// - element: { - get: function () { - return this._element; - } - }, - - /// - /// Gets or sets a value that indicates whether the AppBarCommand is disabled. A value of true disables the AppBarCommand, and a value of false enables it. - /// - disabled: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return !!this._element.disabled; - }, - set: function (value) { - this._element.disabled = value; - } - }, - - /// - hidden: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return this._element.style.visibility === "hidden"; - }, - set: function (value) { - if (value === this.hidden) { - // No changes to make. - return; - } - - var style = this._element.style; - var originalVisibility = style.visibility; - var originalDisplay = style.display; - - if (value) { - style.visibility = "hidden"; - style.display = "none"; - } else { - style.visibility = ""; - style.display = "inline-block"; - } - - if (!this._sendEvent(_Constants.commandVisibilityChanged)) { - style.visibility = originalVisibility; - style.display = originalDisplay; - } - } - }, - - /// - /// Gets or sets the HTMLElement within a "content" type AppBarCommand that should receive focus whenever focus moves via Home or the arrow keys, - /// from the previous AppBarCommand to the this AppBarCommand. Returns the AppBarCommand object's host element by default. - /// - firstElementFocus: { - get: function () { - return this._firstElementFocus || this._lastElementFocus || this._element; - }, - set: function (element) { - // Arguments of null and this.element should treated the same to ensure that this.element is never a tabstop when either focus property has been set. - this._firstElementFocus = (element === this.element) ? null : element; - this._updateTabStop(); - } - }, - - /// - /// Gets or sets the HTMLElement within a "content" type AppBarCommand that should receive focus whenever focus would move, via End or arrow keys, - /// from the next AppBarCommand to this AppBarCommand. Returns this AppBarCommand object's host element by default. - /// - lastElementFocus: { - get: function () { - return this._lastElementFocus || this._firstElementFocus || this._element; - }, - set: function (element) { - // Arguments of null and this.element should treated the same to ensure that this.element is never a tabstop when either focus property has been set. - this._lastElementFocus = (element === this.element) ? null : element; - this._updateTabStop(); - } - }, - - dispose: function () { - /// - /// - /// Disposes this control. - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - - if (this._tooltipControl) { - this._tooltipControl.dispose(); - } - - if (this._type === _Constants.typeContent) { - _Dispose.disposeSubTree(this.element); - } - }, - - addEventListener: function (type, listener, useCapture) { - /// - /// - /// Registers an event handler for the specified event. - /// - /// - /// Required. The name of the event to register. - /// - /// Required. The event handler function to associate with this event. - /// - /// Optional. Set to true to register the event handler for the capturing phase; otherwise, set to false to register the event handler for the bubbling phase. - /// - /// - return this._element.addEventListener(type, listener, useCapture); - }, - - removeEventListener: function (type, listener, useCapture) { - /// - /// - /// Removes an event handler that the addEventListener method registered. - /// - /// Required. The name of the event to remove. - /// Required. The event handler function to remove. - /// - /// Optional. Set to true to remove the capturing phase event handler; otherwise, set to false to remove the bubbling phase event handler. - /// - /// - return this._element.removeEventListener(type, listener, useCapture); - }, - - /// Adds an extra CSS class during construction. - extraClass: { - get: function () { - return this._extraClass; - }, - set: function (value) { - if (this._extraClass) { - _ElementUtilities.removeClass(this._element, this._extraClass); - } - this._extraClass = value; - _ElementUtilities.addClass(this._element, this._extraClass); - } - }, - - // Private - _testIdenticalTooltip: function AppBarCommand_testIdenticalToolTip() { - this._hideIfFullSize = (this._label === this._tooltip); - }, - - _createContent: function AppBarCommand_createContent() { - // Make sure there's an element - if (!this._element) { - this._element = _Global.document.createElement("div"); - } else { - // Verify the element was a div - if (this._element.tagName !== "DIV") { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.BadDivElement", strings.badDivElement); - } - } - - // If a tabIndex isnt set, default to 0; - if (parseInt(this._element.getAttribute("tabIndex"), 10) !== this._element.tabIndex) { - this._element.tabIndex = 0; - } - }, - - _createSeparator: function AppBarCommand_createSeparator() { - // Make sure there's an element - if (!this._element) { - this._element = _Global.document.createElement("hr"); - } else { - // Verify the element was an hr - if (this._element.tagName !== "HR") { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.BadHrElement", strings.badHrElement); - } - } - }, - - _createButton: function AppBarCommand_createButton() { - // Make sure there's an element - if (!this._element) { - this._element = _Global.document.createElement("button"); - } else { - // Verify the element was a button - if (this._element.tagName !== "BUTTON") { - throw new _ErrorFromName("WinJS.UI.AppBarCommand.BadButtonElement", strings.badButtonElement); - } - // Make sure it has a type="button" - var type = this._element.getAttribute("type"); - if (type === null || type === "" || type === undefined) { - this._element.setAttribute("type", "button"); - } - this._element.innerHTML = ""; - } - - // AppBarCommand buttons need to look like this: - //// - this._element.type = "button"; - this._iconSpan = _Global.document.createElement("span"); - this._iconSpan.setAttribute("aria-hidden", "true"); - this._iconSpan.className = "win-commandicon"; - this._iconSpan.tabIndex = -1; - this._element.appendChild(this._iconSpan); - this._imageSpan = _Global.document.createElement("span"); - this._imageSpan.setAttribute("aria-hidden", "true"); - this._imageSpan.className = "win-commandimage"; - this._imageSpan.tabIndex = -1; - this._iconSpan.appendChild(this._imageSpan); - this._labelSpan = _Global.document.createElement("span"); - this._labelSpan.setAttribute("aria-hidden", "true"); - this._labelSpan.className = "win-label"; - this._labelSpan.tabIndex = -1; - this._element.appendChild(this._labelSpan); - // 'win-global' or 'win-selection' are added later by caller. - // Label and icon are added later by caller. - - // Attach a tooltip - Note: we're going to stomp on it's setControl so we don't have to make another DOM element to hang it off of. - // This private _tooltipControl attribute is used by other pieces, changing the name could break them. - this._tooltipControl = new Tooltip.Tooltip(this._element); - var that = this; - this._tooltipControl.addEventListener("beforeopen", function () { - if (that._hideIfFullSize && !_Overlay._Overlay._getParentControlUsingClassName(that._element.parentElement, _Constants.reducedClass)) { - that._tooltipControl.close(); - } - }, false); - }, - - _setSection: function AppBarCommand_setSection(section) { - if (!section) { - section = _Constants.sectionPrimary; - } - - // _Constants.sectionSelection and _Constants.sectionGlobal are deprecated, so we will continue - // adding/removing its corresponding CSS class for app compat. - // _Constants.sectionPrimary and _Constants.sectionSecondary no longer apply CSS classes to the - // commands. - - if (this._section) { - // Remove the old section class - if (this._section === _Constants.sectionGlobal) { - _ElementUtilities.removeClass(this._element, _Constants.appBarCommandGlobalClass); - } else if (this.section === _Constants.sectionSelection) { - _ElementUtilities.removeClass(this._element, _Constants.appBarCommandSelectionClass); - } - } - // Add the new section class - this._section = section; - if (section === _Constants.sectionGlobal) { - _ElementUtilities.addClass(this._element, _Constants.appBarCommandGlobalClass); - } else if (section === _Constants.sectionSelection) { - _ElementUtilities.addClass(this._element, _Constants.appBarCommandSelectionClass); - } - }, - - _updateTabStop: function AppBarCommand_updateTabStop() { - // Whenever the firstElementFocus or lastElementFocus properties are set for content type AppBarCommands, - // the containing command element is no longer a tabstop. - - if (this._firstElementFocus || this._lastElementFocus) { - this.element.tabIndex = -1; - } else { - this.element.tabIndex = 0; - } - }, - - _isFocusable: function AppBarCommand_isFocusable() { - return (!this.hidden && this._type !== _Constants.typeSeparator && !this.element.disabled && - (this.firstElementFocus.tabIndex >= 0 || this.lastElementFocus.tabIndex >= 0)); - }, - - _sendEvent: function AppBarCommand_sendEvent(eventName, detail) { - if (this._disposed) { - return; - } - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(eventName, true, true, (detail || {})); - return this._element.dispatchEvent(event); - }, - }); - - - // The list of AppBarCommand properties that we care about firing an event - // for, whenever they are changed after initial construction. - var ObservablePropertyWhiteList = [ - "label", - "disabled", - "flyout", - "extraClass", - "selected", - "onclick", - "hidden", - ]; - - function makeObservable(command, propertyName) { - // Make a pre-existing AppBarCommand property observable by firing the "_commandpropertymutated" - // event whenever its value changes. - - // Preserve initial value in JS closure variable - var _value = command[propertyName]; - - // Preserve original getter/setter if they exist, else use inline proxy functions. - var proto = command.constructor.prototype; - var originalDesc = getPropertyDescriptor(proto, propertyName) || {}; - var getter = originalDesc.get.bind(command) || function getterProxy() { - return _value; - }; - var setter = originalDesc.set.bind(command) || function setterProxy(value) { - _value = value; - }; - - // Define new observable Get/Set for propertyName on the command instance - Object.defineProperty(command, propertyName, { - get: function observable_get() { - return getter(); - }, - set: function observable_set(value) { - - var oldValue = getter(); - - // Process value through the original setter & getter before deciding to send an event. - setter(value); - var newValue = getter(); - if (!this._disposed && oldValue !== value && oldValue !== newValue && !command._disposed) { - - command._propertyMutations.dispatchEvent( - _Constants.commandPropertyMutated, - { - command: command, - propertyName: propertyName, - oldValue: oldValue, - newValue: newValue, - }); - } - } - }); - } - - function getPropertyDescriptor(obj, propertyName) { - // Returns a matching property descriptor, or null, - // if no matching descriptor is found. - var desc = null; - while (obj && !desc) { - desc = Object.getOwnPropertyDescriptor(obj, propertyName); - obj = Object.getPrototypeOf(obj); - // Walk obj's prototype chain until we find a match. - } - return desc; - } - - return AppBarCommand; - }) - }); - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - Command: _Base.Namespace._lazy(function () { return exports.AppBarCommand; }) - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// Menu Command -/// appbar,appbars,Flyout,Flyouts,onclick,Statics -define('WinJS/Controls/Menu/_Command',[ - 'exports', - '../../Core/_Global', - '../../Core/_Base', - '../../Core/_ErrorFromName', - '../../Core/_Resources', - '../../Promise', - '../../Utilities/_Control', - '../../Utilities/_ElementUtilities', - '../_LegacyAppBar/_Constants', - '../Flyout/_Overlay' -], function menuCommandInit(exports, _Global, _Base, _ErrorFromName, _Resources, Promise, _Control, _ElementUtilities, _Constants, _Overlay) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// Represents a command to be displayed in a Menu. MenuCommand objects provide button, toggle button, flyout button, - /// or separator functionality for Menu controls. - /// - /// - /// - /// - /// - /// ]]> - /// The MenuCommand control itself - /// - /// - MenuCommand: _Base.Namespace._lazy(function () { - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/menuCommandAriaLabel").value; }, - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get badClick() { return "Invalid argument: The onclick property for an {0} must be a function"; }, - get badHrElement() { return "Invalid argument: For a separator, the element must be null or an hr element"; }, - get badButtonElement() { return "Invalid argument: For a button, toggle, or flyout command, the element must be null or a button element"; } - }; - - var MenuCommand = _Base.Class.define(function MenuCommand_ctor(element, options) { - /// - /// - /// Creates a new MenuCommand object. - /// - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the new MenuCommand. - /// - /// - /// A MenuCommand control. - /// - /// - /// - - // Check to make sure we weren't duplicated - if (element && element.winControl) { - throw new _ErrorFromName("WinJS.UI.MenuCommand.DuplicateConstruction", strings.duplicateConstruction); - } - - this._disposed = false; - - // Don't blow up if they didn't pass options - if (!options) { - options = {}; - } - - // Need a type before we can create our element - if (!options.type) { - this._type = _Constants.typeButton; - } - - // Go ahead and create it, separator types look different than buttons - // Don't forget to use passed in element if one was provided. - this._element = element; - if (options.type === _Constants.typeSeparator) { - this._createSeparator(); - } else { - // This will also set the icon & label - this._createButton(); - } - _ElementUtilities.addClass(this._element, "win-disposable"); - - // Remember ourselves - this._element.winControl = this; - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.menuCommandClass); - - if (!options.selected && options.type === _Constants.typeToggle) { - // Make sure toggle's have selected false for CSS - this.selected = false; - } - - if (options.onclick) { - this.onclick = options.onclick; - } - options.onclick = this._handleClick.bind(this); - - _Control.setOptions(this, options); - - // Set our options - if (this._type !== _Constants.typeSeparator) { - // Make sure we have an ARIA role - var role = this._element.getAttribute("role"); - if (role === null || role === "" || role === undefined) { - role = "menuitem"; - if (this._type === _Constants.typeToggle) { - role = "menuitemcheckbox"; - } - this._element.setAttribute("role", role); - if (this._type === _Constants.typeFlyout) { - this._element.setAttribute("aria-haspopup", true); - } - } - var label = this._element.getAttribute("aria-label"); - if (label === null || label === "" || label === undefined) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - } - - }, { - /// - /// Gets the ID of the MenuCommand. - /// - /// - id: { - get: function () { - return this._element.id; - }, - set: function (value) { - // we allow setting first time only. otherwise we ignore it. - if (!this._element.id) { - this._element.id = value; - } - } - }, - - /// - /// Gets the type of the MenuCommand. Possible values are "button", "toggle", "flyout", or "separator". - /// - /// - type: { - get: function () { - return this._type; - }, - set: function (value) { - // we allow setting first time only. otherwise we ignore it. - if (!this._type) { - if (value !== _Constants.typeButton && value !== _Constants.typeFlyout && value !== _Constants.typeToggle && value !== _Constants.typeSeparator) { - value = _Constants.typeButton; - } - - this._type = value; - - if (value === _Constants.typeButton) { - _ElementUtilities.addClass(this.element, _Constants.menuCommandButtonClass); - } else if (value === _Constants.typeFlyout) { - _ElementUtilities.addClass(this.element, _Constants.menuCommandFlyoutClass); - this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false); - } else if (value === _Constants.typeSeparator) { - _ElementUtilities.addClass(this.element, _Constants.menuCommandSeparatorClass); - } else if (value === _Constants.typeToggle) { - _ElementUtilities.addClass(this.element, _Constants.menuCommandToggleClass); - } - } - } - }, - - /// - /// The label of the MenuCommand - /// - /// - label: { - get: function () { - return this._label; - }, - set: function (value) { - this._label = value || ""; - if (this._labelSpan) { - this._labelSpan.textContent = this.label; - } - - // Update aria-label - this._element.setAttribute("aria-label", this.label); - } - }, - - /// - /// Gets or sets the function to invoke when the command is clicked. - /// - /// - onclick: { - get: function () { - return this._onclick; - }, - set: function (value) { - if (value && typeof value !== "function") { - throw new _ErrorFromName("WinJS.UI.MenuCommand.BadClick", _Resources._formatString(strings.badClick, "MenuCommand")); - } - this._onclick = value; - } - }, - - /// - /// For flyout type MenuCommands, this property returns the WinJS.UI.Flyout that this command invokes. When setting this property, you can set - /// it to the string ID of the Flyout, the DOM object that hosts the Flyout, or the Flyout object itself. - /// - /// - flyout: { - get: function () { - // Resolve it to the flyout - var flyout = this._flyout; - if (typeof flyout === "string") { - flyout = _Global.document.getElementById(flyout); - } - // If it doesn't have a .element, then we need to getControl on it - if (flyout && !flyout.element) { - flyout = flyout.winControl; - } - - return flyout; - }, - set: function (value) { - - // Need to update aria-owns with the new ID. - var id = value; - if (id && typeof id !== "string") { - // Our controls have .element properties - if (id.element) { - id = id.element; - } - // Hope it's a DOM element, get ID from DOM element - if (id) { - if (id.id) { - id = id.id; - } else { - // No id, have to fake one - id.id = _ElementUtilities._uniqueID(id); - id = id.id; - } - } - } - if (typeof id === "string") { - this._element.setAttribute("aria-owns", id); - } - - if (this._flyout !== value) { - MenuCommand._deactivateFlyoutCommand(this); - } - - // Remember it - this._flyout = value; - } - }, - - /// - /// Gets or sets the selected state of a toggle button. This property is true if the toggle button is selected; otherwise, it's false. - /// - /// - selected: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return this._element.getAttribute("aria-checked") === "true"; - }, - set: function (value) { - this._element.setAttribute("aria-checked", !!value); - } - }, - - /// - element: { - get: function () { - return this._element; - } - }, - - /// - /// Gets or sets a value that indicates whether the MenuCommand is disabled. This value is true if the MenuCommand is disabled; otherwise, false. - /// - /// - disabled: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return !!this._element.disabled; - }, - set: function (value) { - value = !!value; - if (value && this.type === _Constants.typeFlyout) { - MenuCommand._deactivateFlyoutCommand(this); - } - this._element.disabled = value; - } - }, - - /// - hidden: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return this._element.style.visibility === "hidden"; - }, - set: function (value) { - var menuControl = _Overlay._Overlay._getParentControlUsingClassName(this._element, _Constants.menuClass); - if (menuControl && !menuControl.hidden) { - throw new _ErrorFromName("WinJS.UI.MenuCommand.CannotChangeHiddenProperty", _Resources._formatString(_Overlay._Overlay.commonstrings.cannotChangeHiddenProperty, "Menu")); - } - - var style = this._element.style; - if (value) { - if (this.type === _Constants.typeFlyout) { - MenuCommand._deactivateFlyoutCommand(this); - } - style.visibility = "hidden"; - style.display = "none"; - } else { - style.visibility = ""; - style.display = "block"; - } - } - }, - - /// - /// Gets or sets the extra CSS class that is applied to the host DOM element. - /// - /// - extraClass: { - get: function () { - return this._extraClass; - }, - set: function (value) { - if (this._extraClass) { - _ElementUtilities.removeClass(this._element, this._extraClass); - } - this._extraClass = value; - _ElementUtilities.addClass(this._element, this._extraClass); - } - }, - - - dispose: function () { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - }, - - addEventListener: function (type, listener, useCapture) { - /// - /// - /// Registers an event handler for the specified event. - /// - /// The name of the event to register. - /// The function that handles the event. - /// - /// Set to true to register the event handler for the capturing phase; otherwise, set to false to register the event handler for the bubbling phase. - /// - /// - /// - return this._element.addEventListener(type, listener, useCapture); - }, - - removeEventListener: function (type, listener, useCapture) { - /// - /// - /// Removes the specified event handler that the addEventListener method registered. - /// - /// The name of the event to remove. - /// The event handler function to remove. - /// - /// Set to true to remove the capturing phase event handler; set to false to remove the bubbling phase event handler. - /// - /// - /// - return this._element.removeEventListener(type, listener, useCapture); - }, - - // Private properties - _createSeparator: function MenuCommand_createSeparator() { - // Make sure there's an input element - if (!this._element) { - this._element = _Global.document.createElement("hr"); - } else { - // Verify the input was an hr - if (this._element.tagName !== "HR") { - throw new _ErrorFromName("WinJS.UI.MenuCommand.BadHrElement", strings.badHrElement); - } - } - }, - - _createButton: function MenuCommand_createButton() { - // Make sure there's an element - if (!this._element) { - this._element = _Global.document.createElement("button"); - } else { - // Verify the input was a button - if (this._element.tagName !== "BUTTON") { - throw new _ErrorFromName("WinJS.UI.MenuCommand.BadButtonElement", strings.badButtonElement); - } - } - - // Create our inner HTML. We will set aria values on the button itself further down in the constructor. - this._element.innerHTML = - '
' + - '' + - '' + - '' + - '
'; - this._element.type = "button"; - - // The purpose of menuCommandLiner is to lay out the MenuCommand's children in a flexbox. Ideally, this flexbox would - // be on MenuCommand.element. However, firefox lays out buttons with display:flex differently. - // Firefox bug 1014285 (Button with display:inline-flex doesn't layout properly) - // https://bugzilla.mozilla.org/show_bug.cgi?id=1014285 - this._menuCommandLiner = this._element.firstElementChild; - this._toggleSpan = this._menuCommandLiner.firstElementChild; - this._labelSpan = this._toggleSpan.nextElementSibling; - this._flyoutSpan = this._labelSpan.nextElementSibling; - - }, - _sendEvent: function MenuCommand_sendEvent(eventName, detail) { - if (!this._disposed) { - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(eventName, true, true, (detail || {})); - this._element.dispatchEvent(event); - } - }, - - _invoke: function MenuCommand_invoke(event) { - if (!this.hidden && !this.disabled && !this._disposed) { - if (this._type === _Constants.typeToggle) { - this.selected = !this.selected; - } else if (this._type === _Constants.typeFlyout) { - MenuCommand._activateFlyoutCommand(this); - } - - if (event && event.type === "click" && this.onclick) { - this.onclick(event); - } - - // Bubble private 'invoked' event to Menu - this._sendEvent(_Constants._menuCommandInvokedEvent, { command: this }); - } - }, - - _handleClick: function MenuCommand_handleClick(event) { - this._invoke(event); - }, - - _handleKeyDown: function MenuCommand_handleKeyDown(event) { - var Key = _ElementUtilities.Key, - rtl = _Global.getComputedStyle(this.element).direction === "rtl", - rightKey = rtl ? Key.leftArrow : Key.rightArrow; - - if (event.keyCode === rightKey && this.type === _Constants.typeFlyout) { - this._invoke(event); - - // Prevent the page from scrolling - event.preventDefault(); - } - }, - }, { - // Statics - _activateFlyoutCommand: function MenuCommand_activateFlyoutCommand(menuCommand) { - // Activates the associated Flyout command and returns a promise once complete. - // A command is considered to be activated once the proper CSS class has been applied and its associated flyout has finished showing. - return new Promise(function (c, e) { - menuCommand = menuCommand.winControl || menuCommand; - var subFlyout = menuCommand.flyout; - // Flyout may not have processAll'd, so this may be a DOM object - if (subFlyout && subFlyout.hidden && subFlyout.show) { - _ElementUtilities.addClass(menuCommand.element, _Constants.menuCommandFlyoutActivatedClass); - - // Remove activation class from the command if the flyout is ever hidden. - subFlyout.addEventListener("beforehide", function beforeHide() { - subFlyout.removeEventListener("beforehide", beforeHide, false); - _ElementUtilities.removeClass(menuCommand.element, _Constants.menuCommandFlyoutActivatedClass); - }, false); - - subFlyout.addEventListener("aftershow", function afterShow() { - subFlyout.removeEventListener("aftershow", afterShow, false); - // We are considered activated once we start showing the flyout. - c(); - }, false); - - subFlyout.show(menuCommand, "_cascade"); - } else { - // Could not change command to activated state. - e(); - } - }); - }, - - _deactivateFlyoutCommand: function MenuCommand_deactivateFlyoutCommand(menuCommand) { - // Deactivates the associated Flyout command and returns a promise once complete. - // A command is considered to be deactivated once the proper CSS class has been applied and its associated flyout has finished hiding. - return new Promise(function (c) { - menuCommand = menuCommand.winControl || menuCommand; - _ElementUtilities.removeClass(menuCommand.element, _Constants.menuCommandFlyoutActivatedClass); - - var subFlyout = menuCommand.flyout; - // Flyout may not have processAll'd, so this may be a DOM object - if (subFlyout && !subFlyout.hidden && subFlyout.hide) { - - subFlyout.addEventListener("afterhide", function afterHide() { - subFlyout.removeEventListener("afterhide", afterHide, false); - c(); - }, false); - - subFlyout.hide(); - } else { - // subFlyout does not need to be hidden. - c(); - } - }); - }, - }); - return MenuCommand; - }) - }); - -}); - - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -define('WinJS/Controls/CommandingSurface/_MenuCommand',["require", "exports", "../Menu/_Command"], function (require, exports, _MenuCommandBase) { - var _MenuCommand = (function (_super) { - __extends(_MenuCommand, _super); - function _MenuCommand(element, options) { - if (options && options.beforeInvoke) { - this._beforeInvoke = options.beforeInvoke; - } - _super.call(this, element, options); - } - _MenuCommand.prototype._invoke = function (event) { - this._beforeInvoke && this._beforeInvoke(event); - _super.prototype._invoke.call(this, event); - }; - return _MenuCommand; - })(_MenuCommandBase.MenuCommand); - exports._MenuCommand = _MenuCommand; -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Utilities/_OpenCloseMachine',["require", "exports", '../Core/_Global', '../Promise', '../_Signal'], function (require, exports, _Global, Promise, _Signal) { - "use strict"; - // This module provides a state machine which is designed to be used by controls which need to - // open, close, and fire related events (e.g. beforeopen, afterclose). The state machine handles - // many edge cases. For example, what happens if: - // - open is called when we're already opened? - // - close is called while we're in the middle of opening? - // - dispose is called while we're in the middle of firing beforeopen? - // The state machine takes care of all of these edge cases so that the control doesn't have to. - // The control is responible for knowing how to play its open/close animations and update its DOM. - // The state machine is responsible for ensuring that these things happen at the appropriate times. - // This module is broken up into 3 major pieces: - // - OpenCloseMachine: Controls should instantiate one of these. The machine keeps track of the - // current state and has methods for forwarding calls to the current state. - // - IOpenCloseControl: Controls must provide an object which implements this interface. The - // interface gives the machine hooks for invoking the control's open and close animations. - // - States: The various states (e.g. Closed, Opened, Opening) that the machine can be in. Each - // implements IOpenCloseState. - // Example usage: - // class MyControl { - // element: HTMLElement; - // private _machine: OpenCloseMachine; - // - // constructor(element?: HTMLElement, options: any = {}) { - // this.element = element || document.createElement("div"); - // - // // Create the machine. - // this._machine = new OpenCloseMachine({ - // eventElement: this.element, - // onOpen: (): Promise => { - // // Do the work to render the contol in its opened state with an animation. - // // Return the animation promise. - // }, - // onClose: (): Promise => { - // // Do the work to render the contol in its closed state with an animation. - // // Return the animation promise. - // }, - // onUpdateDom() { - // // Do the work to render the internal state of the control to the DOM. If a - // // control restricts all its DOM modifications to onUpdateDom, the state machine - // // can guarantee that the control won't modify its DOM while it is animating. - // }, - // onUpdateDomWithIsOpened: (isOpened: boolean ) => { - // // Do the same work as onUpdateDom but ensure that the DOM is rendered with either - // // the opened or closed visual as dictacted by isOpened. The control should have some - // // internal state to track whether it is currently opened or closed. Treat this as a - // // cue to mutate that internal state to reflect the value of isOpened. - // }, - // }); - // - // // Initialize the control. During this time, the machine will not ask the control to - // // play any animations or update its DOM. - // this.opened = true; - // _Control.setOptions(this, options); - // - // // Tell the machine the control is initialized. After this, the machine will start asking - // // the control to play animations and update its DOM as appropriate. - // this._machine.exitInit(); - // } - // - // get opened() { - // return this._machine.opened; - // } - // set opened(value: boolean) { - // this._machine.opened = value; - // } - // open() { - // this._machine.open(); - // } - // close() { - // this._machine.close(); - // } - // forceLayout() { - // this._machine.updateDom(); - // } - // dispose() { - // this._machine.dispose(); - // } - // } - var EventNames = { - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose", - // Private events - // Indicates that the OpenCloseMachine has settled either into the Opened state - // or Closed state. This is more comprehensive than the "afteropen" and "afterclose" - // events because it fires even if the machine has reached the state due to: - // - Exiting the Init state - // - The beforeopen/beforeclose events being canceled - _openCloseStateSettled: "_openCloseStateSettled" - }; - // - // OpenCloseMachine - // - var OpenCloseMachine = (function () { - // - // Methods called by the control - // - // When the machine is created, it sits in the Init state. When in the Init state, calls to - // updateDom will be postponed until the machine exits the Init state. Consequently, while in - // this state, the control can feel free to call updateDom as many times as it wants without - // worrying about it being expensive due to updating the DOM many times. The control should call - // *exitInit* to move the machine out of the Init state. - function OpenCloseMachine(args) { - this._control = args; - this._initializedSignal = new _Signal(); - this._disposed = false; - this._setState(States.Init); - } - // Moves the machine out of the Init state and into the Opened or Closed state depending on whether - // open or close was called more recently. - OpenCloseMachine.prototype.exitInit = function () { - this._initializedSignal.complete(); - }; - // These method calls are forwarded to the current state. - OpenCloseMachine.prototype.updateDom = function () { - this._state.updateDom(); - }; - OpenCloseMachine.prototype.open = function () { - this._state.open(); - }; - OpenCloseMachine.prototype.close = function () { - this._state.close(); - }; - Object.defineProperty(OpenCloseMachine.prototype, "opened", { - get: function () { - return this._state.opened; - }, - set: function (value) { - if (value) { - this.open(); - } - else { - this.close(); - } - }, - enumerable: true, - configurable: true - }); - // Puts the machine into the Disposed state. - OpenCloseMachine.prototype.dispose = function () { - this._setState(States.Disposed); - this._disposed = true; - this._control = null; - }; - // - // Methods called by states - // - OpenCloseMachine.prototype._setState = function (NewState, arg0) { - if (!this._disposed) { - this._state && this._state.exit(); - this._state = new NewState(); - this._state.machine = this; - this._state.enter(arg0); - } - }; - // Triggers arbitrary app code - OpenCloseMachine.prototype._fireEvent = function (eventName, options) { - options = options || {}; - var detail = options.detail || null; - var cancelable = !!options.cancelable; - var eventObject = _Global.document.createEvent("CustomEvent"); - eventObject.initCustomEvent(eventName, true, cancelable, detail); - return this._control.eventElement.dispatchEvent(eventObject); - }; - // Triggers arbitrary app code - OpenCloseMachine.prototype._fireBeforeOpen = function () { - return this._fireEvent(EventNames.beforeOpen, { - cancelable: true - }); - }; - // Triggers arbitrary app code - OpenCloseMachine.prototype._fireBeforeClose = function () { - return this._fireEvent(EventNames.beforeClose, { - cancelable: true - }); - }; - return OpenCloseMachine; - })(); - exports.OpenCloseMachine = OpenCloseMachine; - // - // States (each implements IOpenCloseState) - // - // WinJS animation promises always complete successfully. This - // helper allows an animation promise to complete in the canceled state - // so that the success handler can be skipped when the animation is - // interrupted. - function cancelablePromise(animationPromise) { - return Promise._cancelBlocker(animationPromise, function () { - animationPromise.cancel(); - }); - } - // Noop function, used in the various states to indicate that they don't support a given - // message. Named with the somewhat cute name '_' because it reads really well in the states. - function _() { - } - // Implementing the control as a state machine helps us correctly handle: - // - re-entrancy while firing events - // - calls into the control during asynchronous operations (e.g. animations) - // - // Many of the states do their "enter" work within a promise chain. The idea is that if - // the state is interrupted and exits, the rest of its work can be skipped by canceling - // the promise chain. - // An interesting detail is that anytime the state may trigger app code (e.g. due to - // firing an event), the current promise must end and a new promise must be chained off of it. - // This is necessary because the app code may interact with the control and cause it to - // change states. If we didn't create a new promise, then the very next line of code that runs - // after triggering app code may not be valid because the state may have exited. Starting a - // new promise after each triggering of app code prevents us from having to worry about this - // problem. In this configuration, when a promise's success handler runs, it guarantees that - // the state hasn't exited. - // For similar reasons, each of the promise chains created in "enter" starts off with a _Signal - // which is completed at the end of the "enter" function (this boilerplate is abstracted away by - // the "interruptible" function). The reason is that we don't want any of the code in "enter" - // to run until the promise chain has been stored in a variable. If we didn't do this (e.g. instead, - // started the promise chain with Promise.wrap()), then the "enter" code could trigger the "exit" - // function (via app code) before the promise chain had been stored in a variable. Under these - // circumstances, the promise chain would be uncancelable and so the "enter" work would be - // unskippable. This wouldn't be good when we needed the state to exit early. - // These two functions manage interruptible work promises (one creates them the other cancels - // them). They communicate with each other thru the _interruptibleWorkPromises property which - // "interruptible" creates on your object. - function interruptible(object, workFn) { - object["_interruptibleWorkPromises"] = object["_interruptibleWorkPromises"] || []; - var workStoredSignal = new _Signal(); - object["_interruptibleWorkPromises"].push(workFn(workStoredSignal.promise)); - workStoredSignal.complete(); - } - function cancelInterruptibles() { - (this["_interruptibleWorkPromises"] || []).forEach(function (workPromise) { - workPromise.cancel(); - }); - } - // Transitions: - // When created, the state machine will take one of the following initialization - // transitions depending on how the machines's APIs have been used by the time - // exitInit() is called on it: - // Init -> Closed - // Init -> Opened - // Following that, the life of the machine will be dominated by the following - // sequences of transitions. In geneneral, these sequences are uninterruptible. - // Closed -> BeforeOpen -> Closed (when preventDefault is called on beforeopen event) - // Closed -> BeforeOpen -> Opening -> Opened - // Opened -> BeforeClose -> Opened (when preventDefault is called on beforeclose event) - // Opened -> BeforeClose -> Closing -> Closed - // However, any state can be interrupted to go to the Disposed state: - // * -> Disposed - var States; - (function (States) { - function updateDomImpl() { - this.machine._control.onUpdateDom(); - } - // Initial state. Gives the control the opportunity to initialize itself without - // triggering any animations or DOM modifications. When done, the control should - // call *exitInit* to move the machine to the next state. - var Init = (function () { - function Init() { - this.name = "Init"; - this.exit = cancelInterruptibles; - this.updateDom = _; // Postponed until immediately before we switch to another state - } - Init.prototype.enter = function () { - var _this = this; - interruptible(this, function (ready) { - return ready.then(function () { - return _this.machine._initializedSignal.promise; - }).then(function () { - _this.machine._control.onUpdateDomWithIsOpened(_this._opened); - _this.machine._setState(_this._opened ? Opened : Closed); - }); - }); - }; - Object.defineProperty(Init.prototype, "opened", { - get: function () { - return this._opened; - }, - enumerable: true, - configurable: true - }); - Init.prototype.open = function () { - this._opened = true; - }; - Init.prototype.close = function () { - this._opened = false; - }; - return Init; - })(); - States.Init = Init; - // A rest state. The control is closed and is waiting for the app to call open. - var Closed = (function () { - function Closed() { - this.name = "Closed"; - this.exit = _; - this.opened = false; - this.close = _; - this.updateDom = updateDomImpl; - } - Closed.prototype.enter = function (args) { - args = args || {}; - if (args.openIsPending) { - this.open(); - } - this.machine._fireEvent(EventNames._openCloseStateSettled); - }; - Closed.prototype.open = function () { - this.machine._setState(BeforeOpen); - }; - return Closed; - })(); - // An event state. The control fires the beforeopen event. - var BeforeOpen = (function () { - function BeforeOpen() { - this.name = "BeforeOpen"; - this.exit = cancelInterruptibles; - this.opened = false; - this.open = _; - this.close = _; - this.updateDom = updateDomImpl; - } - BeforeOpen.prototype.enter = function () { - var _this = this; - interruptible(this, function (ready) { - return ready.then(function () { - return _this.machine._fireBeforeOpen(); // Give opportunity for chain to be canceled when triggering app code - }).then(function (shouldOpen) { - if (shouldOpen) { - _this.machine._setState(Opening); - } - else { - _this.machine._setState(Closed); - } - }); - }); - }; - return BeforeOpen; - })(); - // An animation/event state. The control plays its open animation and fires afteropen. - var Opening = (function () { - function Opening() { - this.name = "Opening"; - this.exit = cancelInterruptibles; - this.updateDom = _; // Postponed until immediately before we switch to another state - } - Opening.prototype.enter = function () { - var _this = this; - interruptible(this, function (ready) { - return ready.then(function () { - _this._closeIsPending = false; - return cancelablePromise(_this.machine._control.onOpen()); - }).then(function () { - _this.machine._fireEvent(EventNames.afterOpen); // Give opportunity for chain to be canceled when triggering app code - }).then(function () { - _this.machine._control.onUpdateDom(); - _this.machine._setState(Opened, { closeIsPending: _this._closeIsPending }); - }); - }); - }; - Object.defineProperty(Opening.prototype, "opened", { - get: function () { - return !this._closeIsPending; - }, - enumerable: true, - configurable: true - }); - Opening.prototype.open = function () { - this._closeIsPending = false; - }; - Opening.prototype.close = function () { - this._closeIsPending = true; - }; - return Opening; - })(); - // A rest state. The control is opened and is waiting for the app to call close. - var Opened = (function () { - function Opened() { - this.name = "Opened"; - this.exit = _; - this.opened = true; - this.open = _; - this.updateDom = updateDomImpl; - } - Opened.prototype.enter = function (args) { - args = args || {}; - if (args.closeIsPending) { - this.close(); - } - this.machine._fireEvent(EventNames._openCloseStateSettled); - }; - Opened.prototype.close = function () { - this.machine._setState(BeforeClose); - }; - return Opened; - })(); - // An event state. The control fires the beforeclose event. - var BeforeClose = (function () { - function BeforeClose() { - this.name = "BeforeClose"; - this.exit = cancelInterruptibles; - this.opened = true; - this.open = _; - this.close = _; - this.updateDom = updateDomImpl; - } - BeforeClose.prototype.enter = function () { - var _this = this; - interruptible(this, function (ready) { - return ready.then(function () { - return _this.machine._fireBeforeClose(); // Give opportunity for chain to be canceled when triggering app code - }).then(function (shouldClose) { - if (shouldClose) { - _this.machine._setState(Closing); - } - else { - _this.machine._setState(Opened); - } - }); - }); - }; - return BeforeClose; - })(); - // An animation/event state. The control plays the close animation and fires the afterclose event. - var Closing = (function () { - function Closing() { - this.name = "Closing"; - this.exit = cancelInterruptibles; - this.updateDom = _; // Postponed until immediately before we switch to another state - } - Closing.prototype.enter = function () { - var _this = this; - interruptible(this, function (ready) { - return ready.then(function () { - _this._openIsPending = false; - return cancelablePromise(_this.machine._control.onClose()); - }).then(function () { - _this.machine._fireEvent(EventNames.afterClose); // Give opportunity for chain to be canceled when triggering app code - }).then(function () { - _this.machine._control.onUpdateDom(); - _this.machine._setState(Closed, { openIsPending: _this._openIsPending }); - }); - }); - }; - Object.defineProperty(Closing.prototype, "opened", { - get: function () { - return this._openIsPending; - }, - enumerable: true, - configurable: true - }); - Closing.prototype.open = function () { - this._openIsPending = true; - }; - Closing.prototype.close = function () { - this._openIsPending = false; - }; - return Closing; - })(); - var Disposed = (function () { - function Disposed() { - this.name = "Disposed"; - this.enter = _; - this.exit = _; - this.opened = false; - this.open = _; - this.close = _; - this.updateDom = _; - } - return Disposed; - })(); - States.Disposed = Disposed; - })(States || (States = {})); -}); - - -define('require-style!less/styles-commandingsurface',[],function(){}); - -define('require-style!less/colors-commandingsurface',[],function(){}); -define('WinJS/Controls/CommandingSurface/_CommandingSurface',["require", "exports", "../../Animations", "../../Core/_Base", "../../Core/_BaseUtils", "../../BindingList", "../../ControlProcessor", "../CommandingSurface/_Constants", "../AppBar/_Command", "../CommandingSurface/_MenuCommand", "../../Utilities/_Control", "../../Utilities/_Dispose", "../../Utilities/_ElementUtilities", "../../Core/_ErrorFromName", '../../Core/_Events', "../../Controls/Flyout", "../../Core/_Global", "../../Utilities/_Hoverable", "../../Utilities/_KeyboardBehavior", '../../Core/_Log', '../../Promise', "../../Core/_Resources", "../../Scheduler", '../../Utilities/_OpenCloseMachine', '../../_Signal', "../../Core/_WriteProfilerMark"], function (require, exports, Animations, _Base, _BaseUtils, BindingList, ControlProcessor, _Constants, _Command, _CommandingSurfaceMenuCommand, _Control, _Dispose, _ElementUtilities, _ErrorFromName, _Events, _Flyout, _Global, _Hoverable, _KeyboardBehavior, _Log, Promise, _Resources, Scheduler, _OpenCloseMachine, _Signal, _WriteProfilerMark) { - require(["require-style!less/styles-commandingsurface"]); - require(["require-style!less/colors-commandingsurface"]); - "use strict"; - var strings = { - get overflowButtonAriaLabel() { - return _Resources._getWinJSString("ui/commandingSurfaceOverflowButtonAriaLabel").value; - }, - get badData() { - return "Invalid argument: The data property must an instance of a WinJS.Binding.List"; - }, - get mustContainCommands() { - return "The commandingSurface can only contain WinJS.UI.Command or WinJS.UI.AppBarCommand controls"; - }, - get duplicateConstruction() { - return "Invalid argument: Controls may only be instantiated one time for each DOM element"; - } - }; - var CommandLayoutPipeline = { - newDataStage: 3, - measuringStage: 2, - layoutStage: 1, - idle: 0, - }; - var OverflowDirection = { - /// The _CommandingSurface expands towards the bottom of the screen when opened and the overflow area renders below the actionarea. - bottom: "bottom", - /// The _CommandingSurface expands towards the top of the screen when opened and the overflow area renders above the actionarea. - top: "top", - }; - var overflowDirectionClassMap = {}; - overflowDirectionClassMap[OverflowDirection.top] = _Constants.ClassNames.overflowTopClass; - overflowDirectionClassMap[OverflowDirection.bottom] = _Constants.ClassNames.overflowBottomClass; - var ClosedDisplayMode = { - /// When the _CommandingSurface is closed, the actionarea is not visible and doesn't take up any space. - none: "none", - /// When the _CommandingSurface is closed, the height of the actionarea is reduced to the minimal height required to display only the actionarea overflowbutton. All other content in the actionarea is not displayed. - minimal: "minimal", - /// When the _CommandingSurface is closed, the height of the actionarea is reduced such that button commands are still visible, but their labels are hidden. - compact: "compact", - /// When the _CommandingSurface is closed, the height of the actionarea is always sized to content and does not change between opened and closed states. - full: "full", - }; - var closedDisplayModeClassMap = {}; - closedDisplayModeClassMap[ClosedDisplayMode.none] = _Constants.ClassNames.noneClass; - closedDisplayModeClassMap[ClosedDisplayMode.minimal] = _Constants.ClassNames.minimalClass; - closedDisplayModeClassMap[ClosedDisplayMode.compact] = _Constants.ClassNames.compactClass; - closedDisplayModeClassMap[ClosedDisplayMode.full] = _Constants.ClassNames.fullClass; - // Versions of add/removeClass that are no ops when called with falsy class names. - function addClass(element, className) { - className && _ElementUtilities.addClass(element, className); - } - function removeClass(element, className) { - className && _ElementUtilities.removeClass(element, className); - } - function diffElements(lhs, rhs) { - // Subtract array rhs from array lhs. - // Returns a new Array containing the subset of elements in lhs that are not also in rhs. - return lhs.filter(function (commandElement) { - return rhs.indexOf(commandElement) < 0; - }); - } - /// Represents an apaptive surface for displaying commands. - var _CommandingSurface = (function () { - function _CommandingSurface(element, options) { - /// Creates a new CommandingSurface control. - /// @param element: The DOM element that will host the control. - /// @param options: The set of properties and values to apply to the new CommandingSurface control. - /// @return: The new CommandingSurface control. - var _this = this; - if (options === void 0) { options = {}; } - this._hoverable = _Hoverable.isHoverable; /* force dependency on hoverable module */ - this._dataChangedEvents = ["itemchanged", "iteminserted", "itemmoved", "itemremoved", "reload"]; - // State private to _updateDomImpl_renderDisplayMode. No other method should make use of it. - // - // Nothing has been rendered yet so these are all initialized to undefined. Because - // they are undefined, the first time _updateDomImpl is called, they will all be - // rendered. - this._updateDomImpl_renderedState = { - closedDisplayMode: undefined, - isOpenedMode: undefined, - overflowDirection: undefined, - overflowAlignmentOffset: undefined, - }; - this._writeProfilerMark("constructor,StartTM"); - // Check to make sure we weren't duplicated - if (element && element["winControl"]) { - throw new _ErrorFromName("WinJS.UI._CommandingSurface.DuplicateConstruction", strings.duplicateConstruction); - } - this._initializeDom(element || _Global.document.createElement("div")); - this._machine = options.openCloseMachine || new _OpenCloseMachine.OpenCloseMachine({ - eventElement: this._dom.root, - onOpen: function () { - _this.synchronousOpen(); - return Promise.wrap(); - }, - onClose: function () { - _this.synchronousClose(); - return Promise.wrap(); - }, - onUpdateDom: function () { - _this.updateDomImpl(); - }, - onUpdateDomWithIsOpened: function (isOpened) { - if (isOpened) { - _this.synchronousOpen(); - } - else { - _this.synchronousClose(); - } - } - }); - // Initialize private state. - this._disposed = false; - this._primaryCommands = []; - this._secondaryCommands = []; - this._refreshBound = this._refresh.bind(this); - this._resizeHandlerBound = this._resizeHandler.bind(this); - this._winKeyboard = new _KeyboardBehavior._WinKeyboard(this._dom.root); - this._refreshPending = false; - this._rtl = false; - this._initializedSignal = new _Signal(); - this._nextLayoutStage = CommandLayoutPipeline.idle; - this._isOpenedMode = _Constants.defaultOpened; - this._menuCommandProjections = []; - // Initialize public properties. - this.overflowDirection = _Constants.defaultOverflowDirection; - this.closedDisplayMode = _Constants.defaultClosedDisplayMode; - this.opened = this._isOpenedMode; - if (!options.data) { - // Shallow copy object so we can modify it. - options = _BaseUtils._shallowCopy(options); - // Set default data - options.data = options.data || this._getDataFromDOMElements(); - } - _Control.setOptions(this, options); - // Event handlers - _ElementUtilities._resizeNotifier.subscribe(this._dom.root, this._resizeHandlerBound); - this._dom.root.addEventListener('keydown', this._keyDownHandler.bind(this)); - // Exit the Init state. - _ElementUtilities._inDom(this._dom.root).then(function () { - _this._rtl = _Global.getComputedStyle(_this._dom.root).direction === 'rtl'; - if (!options.openCloseMachine) { - // We should only call exitInit on the machine when we own the machine. - _this._machine.exitInit(); - } - _this._initializedSignal.complete(); - _this._writeProfilerMark("constructor,StopTM"); - }); - } - Object.defineProperty(_CommandingSurface.prototype, "element", { - /// Gets the DOM element that hosts the CommandingSurface. - get: function () { - return this._dom.root; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(_CommandingSurface.prototype, "data", { - /// Gets or sets the Binding List of WinJS.UI.Command for the CommandingSurface. - get: function () { - return this._data; - }, - set: function (value) { - this._writeProfilerMark("set_data,info"); - if (value !== this.data) { - if (!(value instanceof BindingList.List)) { - throw new _ErrorFromName("WinJS.UI._CommandingSurface.BadData", strings.badData); - } - if (this._data) { - this._removeDataListeners(); - } - this._data = value; - this._addDataListeners(); - this._dataUpdated(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(_CommandingSurface.prototype, "closedDisplayMode", { - /// Gets or sets the closedDisplayMode for the CommandingSurface. Values are "none", "minimal", "compact", and "full". - get: function () { - return this._closedDisplayMode; - }, - set: function (value) { - this._writeProfilerMark("set_closedDisplayMode,info"); - var isChangingState = (value !== this._closedDisplayMode); - if (ClosedDisplayMode[value] && isChangingState) { - this._closedDisplayMode = value; - this._machine.updateDom(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(_CommandingSurface.prototype, "overflowDirection", { - /// Gets or sets which direction the commandingSurface overflows when opened. Values are "top" and "bottom" for. - get: function () { - return this._overflowDirection; - }, - set: function (value) { - var isChangingState = (value !== this._overflowDirection); - if (OverflowDirection[value] && isChangingState) { - this._overflowDirection = value; - this._machine.updateDom(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(_CommandingSurface.prototype, "opened", { - /// Gets or sets whether the _CommandingSurface is currently opened. - get: function () { - return this._machine.opened; - }, - set: function (value) { - this._machine.opened = value; - }, - enumerable: true, - configurable: true - }); - _CommandingSurface.prototype.open = function () { - /// Opens the _CommandingSurface's actionarea and overflowarea - this._machine.open(); - }; - _CommandingSurface.prototype.close = function () { - /// Closes the _CommandingSurface's actionarea and overflowarea - this._machine.close(); - }; - _CommandingSurface.prototype.dispose = function () { - /// Disposes this CommandingSurface. - if (this._disposed) { - return; - } - this._disposed = true; - this._machine.dispose(); - _ElementUtilities._resizeNotifier.unsubscribe(this._dom.root, this._resizeHandlerBound); - if (this._contentFlyout) { - this._contentFlyout.dispose(); - this._contentFlyout.element.parentNode.removeChild(this._contentFlyout.element); - } - _Dispose.disposeSubTree(this._dom.root); - }; - _CommandingSurface.prototype.forceLayout = function () { - /// Forces the CommandingSurface to update its layout. Use this function when the window did not change - /// size, but the container of the CommandingSurface changed size. - this._meaurementsDirty(); - this._machine.updateDom(); - }; - _CommandingSurface.prototype.getBoundingRects = function () { - return { - commandingSurface: this._dom.root.getBoundingClientRect(), - overflowArea: this._dom.overflowArea.getBoundingClientRect(), - }; - }; - _CommandingSurface.prototype.getCommandById = function (id) { - if (this._data) { - for (var i = 0, len = this._data.length; i < len; i++) { - var command = this._data.getAt(i); - if (command.id === id) { - return command; - } - } - } - return null; - }; - _CommandingSurface.prototype.showOnlyCommands = function (commands) { - if (this._data) { - for (var i = 0, len = this._data.length; i < len; i++) { - this._data.getAt(i).hidden = true; - } - for (var i = 0, len = commands.length; i < len; i++) { - // The array passed to showOnlyCommands can contain either command ids, or the commands themselves. - var command = (typeof commands[i] === "string" ? this.getCommandById(commands[i]) : commands[i]); - if (command) { - command.hidden = false; - } - } - } - }; - _CommandingSurface.prototype.deferredDomUpate = function () { - // Notify the machine that an update has been requested. - this._machine.updateDom(); - }; - _CommandingSurface.prototype.createOpenAnimation = function (closedHeight) { - // createOpenAnimation should only be called when the commanding surface is in a closed state. The control using the commanding surface is expected - // to call createOpenAnimation() before it opens the surface, then open the commanding surface, then call .execute() to start the animation. - // This function is overridden by our unit tests. - if (_Log.log) { - this._updateDomImpl_renderedState.isOpenedMode && _Log.log("The CommandingSurface should only attempt to create an open animation when it's not already opened"); - } - var that = this; - return { - execute: function () { - var boundingRects = that.getBoundingRects(); - // The overflowAreaContainer has no size by default. Measure the overflowArea's size and apply it to the overflowAreaContainer before animating - that._dom.overflowAreaContainer.style.width = boundingRects.overflowArea.width + "px"; - that._dom.overflowAreaContainer.style.height = boundingRects.overflowArea.height + "px"; - return Animations._commandingSurfaceOpenAnimation({ - actionAreaClipper: that._dom.actionAreaContainer, - actionArea: that._dom.actionArea, - overflowAreaClipper: that._dom.overflowAreaContainer, - overflowArea: that._dom.overflowArea, - oldHeight: closedHeight, - newHeight: boundingRects.commandingSurface.height, - overflowAreaHeight: boundingRects.overflowArea.height, - menuPositionedAbove: (that.overflowDirection === OverflowDirection.top), - }).then(function () { - that._clearAnimation(); - }); - } - }; - }; - _CommandingSurface.prototype.createCloseAnimation = function (closedHeight) { - // createCloseAnimation should only be called when the commanding surface is in an opened state. The control using the commanding surface is expected - // to call createCloseAnimation() before it closes the surface, then call execute() to let the animation run. Once the animation finishes, the control - // should close the commanding surface. - // This function is overridden by our unit tests. - if (_Log.log) { - !this._updateDomImpl_renderedState.isOpenedMode && _Log.log("The CommandingSurface should only attempt to create an closed animation when it's not already closed"); - } - var openedHeight = this.getBoundingRects().commandingSurface.height, overflowAreaOpenedHeight = this._dom.overflowArea.offsetHeight, oldOverflowTop = this._dom.overflowArea.offsetTop, that = this; - return { - execute: function () { - _ElementUtilities.addClass(that.element, _Constants.ClassNames.closingClass); - return Animations._commandingSurfaceCloseAnimation({ - actionAreaClipper: that._dom.actionAreaContainer, - actionArea: that._dom.actionArea, - overflowAreaClipper: that._dom.overflowAreaContainer, - overflowArea: that._dom.overflowArea, - oldHeight: openedHeight, - newHeight: closedHeight, - overflowAreaHeight: overflowAreaOpenedHeight, - menuPositionedAbove: (that.overflowDirection === OverflowDirection.top), - }).then(function () { - _ElementUtilities.removeClass(that.element, _Constants.ClassNames.closingClass); - that._clearAnimation(); - }); - } - }; - }; - Object.defineProperty(_CommandingSurface.prototype, "initialized", { - get: function () { - return this._initializedSignal.promise; - }, - enumerable: true, - configurable: true - }); - _CommandingSurface.prototype._writeProfilerMark = function (text) { - _WriteProfilerMark("WinJS.UI._CommandingSurface:" + this._id + ":" + text); - }; - _CommandingSurface.prototype._initializeDom = function (root) { - var _this = this; - this._writeProfilerMark("_intializeDom,info"); - // Attaching JS control to DOM element - root["winControl"] = this; - this._id = root.id || _ElementUtilities._uniqueID(root); - if (!root.hasAttribute("tabIndex")) { - root.tabIndex = -1; - } - _ElementUtilities.addClass(root, _Constants.ClassNames.controlCssClass); - _ElementUtilities.addClass(root, _Constants.ClassNames.disposableCssClass); - var actionArea = _Global.document.createElement("div"); - _ElementUtilities.addClass(actionArea, _Constants.ClassNames.actionAreaCssClass); - _ElementUtilities._reparentChildren(root, actionArea); - var actionAreaContainer = _Global.document.createElement("div"); - _ElementUtilities.addClass(actionAreaContainer, _Constants.ClassNames.actionAreaContainerCssClass); - actionAreaContainer.appendChild(actionArea); - root.appendChild(actionAreaContainer); - var spacer = _Global.document.createElement("div"); - _ElementUtilities.addClass(spacer, _Constants.ClassNames.spacerCssClass); - actionArea.appendChild(spacer); - var overflowButton = _Global.document.createElement("button"); - overflowButton.tabIndex = 0; - overflowButton.innerHTML = ""; - _ElementUtilities.addClass(overflowButton, _Constants.ClassNames.overflowButtonCssClass); - actionArea.appendChild(overflowButton); - overflowButton.addEventListener("click", function () { - _this.opened = !_this.opened; - }); - var overflowArea = _Global.document.createElement("div"); - _ElementUtilities.addClass(overflowArea, _Constants.ClassNames.overflowAreaCssClass); - _ElementUtilities.addClass(overflowArea, _Constants.ClassNames.menuCssClass); - var overflowAreaContainer = _Global.document.createElement("div"); - _ElementUtilities.addClass(overflowAreaContainer, _Constants.ClassNames.overflowAreaContainerCssClass); - overflowAreaContainer.appendChild(overflowArea); - root.appendChild(overflowAreaContainer); - this._dom = { - root: root, - actionArea: actionArea, - actionAreaContainer: actionAreaContainer, - spacer: spacer, - overflowButton: overflowButton, - overflowArea: overflowArea, - overflowAreaContainer: overflowAreaContainer - }; - }; - _CommandingSurface.prototype._getFocusableElementsInfo = function () { - var _this = this; - var focusableCommandsInfo = { - elements: [], - focusedIndex: -1 - }; - var elementsInReach = Array.prototype.slice.call(this._dom.actionArea.children); - var elementsInReach = Array.prototype.slice.call(this._dom.actionArea.children); - if (this._dom.overflowArea.style.display !== "none") { - elementsInReach = elementsInReach.concat(Array.prototype.slice.call(this._dom.overflowArea.children)); - } - elementsInReach.forEach(function (element) { - if (_this._isElementFocusable(element)) { - focusableCommandsInfo.elements.push(element); - if (element.contains(_Global.document.activeElement)) { - focusableCommandsInfo.focusedIndex = focusableCommandsInfo.elements.length - 1; - } - } - }); - return focusableCommandsInfo; - }; - _CommandingSurface.prototype._dataUpdated = function () { - var _this = this; - this._primaryCommands = []; - this._secondaryCommands = []; - if (this.data.length > 0) { - this.data.forEach(function (command) { - if (command.section === "secondary") { - _this._secondaryCommands.push(command); - } - else { - _this._primaryCommands.push(command); - } - }); - } - this._dataDirty(); - this._machine.updateDom(); - }; - _CommandingSurface.prototype._refresh = function () { - var _this = this; - if (!this._refreshPending) { - this._refreshPending = true; - // Batch calls to _dataUpdated - Scheduler.schedule(function () { - if (_this._refreshPending && !_this._disposed) { - _this._refreshPending = false; - _this._dataUpdated(); - } - }, Scheduler.Priority.high, null, "WinJS.UI._CommandingSurface._refresh"); - } - }; - _CommandingSurface.prototype._addDataListeners = function () { - var _this = this; - this._dataChangedEvents.forEach(function (eventName) { - _this._data.addEventListener(eventName, _this._refreshBound, false); - }); - }; - _CommandingSurface.prototype._removeDataListeners = function () { - var _this = this; - this._dataChangedEvents.forEach(function (eventName) { - _this._data.removeEventListener(eventName, _this._refreshBound, false); - }); - }; - _CommandingSurface.prototype._isElementFocusable = function (element) { - var focusable = false; - if (element) { - var command = element["winControl"]; - if (command) { - focusable = command.element.style.display !== "none" && command.type !== _Constants.typeSeparator && !command.hidden && !command.disabled && (!command.firstElementFocus || command.firstElementFocus.tabIndex >= 0 || command.lastElementFocus.tabIndex >= 0); - } - else { - // e.g. the overflow button - focusable = element.style.display !== "none" && getComputedStyle(element).visibility !== "hidden" && element.tabIndex >= 0; - } - } - return focusable; - }; - _CommandingSurface.prototype._isCommandInActionArea = function (element) { - // Returns true if the element is a command in the actionarea, false otherwise - return element && element["winControl"] && element.parentElement === this._dom.actionArea; - }; - _CommandingSurface.prototype._getLastElementFocus = function (element) { - if (this._isCommandInActionArea(element)) { - // Only commands in the actionarea support lastElementFocus - return element["winControl"].lastElementFocus; - } - else { - return element; - } - }; - _CommandingSurface.prototype._getFirstElementFocus = function (element) { - if (this._isCommandInActionArea(element)) { - // Only commands in the actionarea support firstElementFocus - return element["winControl"].firstElementFocus; - } - else { - return element; - } - }; - _CommandingSurface.prototype._keyDownHandler = function (ev) { - if (!ev.altKey) { - if (_ElementUtilities._matchesSelector(ev.target, ".win-interactive, .win-interactive *")) { - return; - } - var Key = _ElementUtilities.Key; - var focusableElementsInfo = this._getFocusableElementsInfo(); - var targetCommand; - if (focusableElementsInfo.elements.length) { - switch (ev.keyCode) { - case (this._rtl ? Key.rightArrow : Key.leftArrow): - case Key.upArrow: - var index = Math.max(0, focusableElementsInfo.focusedIndex - 1); - targetCommand = this._getLastElementFocus(focusableElementsInfo.elements[index % focusableElementsInfo.elements.length]); - break; - case (this._rtl ? Key.leftArrow : Key.rightArrow): - case Key.downArrow: - var index = Math.min(focusableElementsInfo.focusedIndex + 1, focusableElementsInfo.elements.length - 1); - targetCommand = this._getFirstElementFocus(focusableElementsInfo.elements[index]); - break; - case Key.home: - var index = 0; - targetCommand = this._getFirstElementFocus(focusableElementsInfo.elements[index]); - break; - case Key.end: - var index = focusableElementsInfo.elements.length - 1; - targetCommand = this._getLastElementFocus(focusableElementsInfo.elements[index]); - break; - } - } - if (targetCommand && targetCommand !== _Global.document.activeElement) { - targetCommand.focus(); - ev.preventDefault(); - } - } - }; - _CommandingSurface.prototype._getDataFromDOMElements = function () { - this._writeProfilerMark("_getDataFromDOMElements,info"); - ControlProcessor.processAll(this._dom.actionArea, true); - var commands = []; - var childrenLength = this._dom.actionArea.children.length; - var child; - for (var i = 0; i < childrenLength; i++) { - child = this._dom.actionArea.children[i]; - if (child["winControl"] && child["winControl"] instanceof _Command.AppBarCommand) { - commands.push(child["winControl"]); - } - else if (child !== this._dom.overflowButton && child !== this._dom.spacer) { - throw new _ErrorFromName("WinJS.UI._CommandingSurface.MustContainCommands", strings.mustContainCommands); - } - } - return new BindingList.List(commands); - }; - _CommandingSurface.prototype._resizeHandler = function () { - if (this._dom.root.offsetWidth) { - var currentActionAreaWidth = _ElementUtilities._getPreciseContentWidth(this._dom.actionArea); - if (this._cachedMeasurements && this._cachedMeasurements.actionAreaContentBoxWidth !== currentActionAreaWidth) { - this._cachedMeasurements.actionAreaContentBoxWidth = currentActionAreaWidth; - this._layoutDirty(); - this._machine.updateDom(); - } - } - }; - _CommandingSurface.prototype._dataDirty = function () { - this._nextLayoutStage = Math.max(CommandLayoutPipeline.newDataStage, this._nextLayoutStage); - }; - _CommandingSurface.prototype._meaurementsDirty = function () { - this._nextLayoutStage = Math.max(CommandLayoutPipeline.measuringStage, this._nextLayoutStage); - }; - _CommandingSurface.prototype._layoutDirty = function () { - this._nextLayoutStage = Math.max(CommandLayoutPipeline.layoutStage, this._nextLayoutStage); - }; - _CommandingSurface.prototype.synchronousOpen = function () { - this._overflowAlignmentOffset = 0; - this._isOpenedMode = true; - this.updateDomImpl(); - this._overflowAlignmentOffset = this._computeAdjustedOverflowAreaOffset(); - this.updateDomImpl(); - }; - _CommandingSurface.prototype._computeAdjustedOverflowAreaOffset = function () { - // Returns any negative offset needed to prevent the shown overflowarea from clipping outside of the viewport. - // This function should only be called when CommandingSurface has been rendered in the opened state with - // an overflowAlignmentOffset of 0. - if (_Log.log) { - !this._updateDomImpl_renderedState.isOpenedMode && _Log.log("The CommandingSurface should only attempt to compute adjusted overflowArea offset " + " when it has been rendered opened"); - this._updateDomImpl_renderedState.overflowAlignmentOffset !== 0 && _Log.log("The CommandingSurface should only attempt to compute adjusted overflowArea offset " + " when it has been rendered with an overflowAlignementOffset of 0"); - } - var overflowArea = this._dom.overflowArea, boundingClientRects = this.getBoundingRects(), adjustedOffset = 0; - if (this._rtl) { - // In RTL the left edge of overflowarea prefers to align to the LEFT edge of the commandingSurface. - // Make sure we avoid clipping through the RIGHT edge of the viewport - var viewportRight = window.innerWidth, rightOffsetFromViewport = boundingClientRects.overflowArea.right; - adjustedOffset = Math.min(viewportRight - rightOffsetFromViewport, 0); - } - else { - // In LTR the right edge of overflowarea prefers to align to the RIGHT edge of the commandingSurface. - // Make sure we avoid clipping through the LEFT edge of the viewport. - var leftOffsetFromViewport = boundingClientRects.overflowArea.left; - adjustedOffset = Math.min(0, leftOffsetFromViewport); - } - return adjustedOffset; - }; - _CommandingSurface.prototype.synchronousClose = function () { - this._isOpenedMode = false; - this.updateDomImpl(); - }; - _CommandingSurface.prototype.updateDomImpl = function () { - this._updateDomImpl_renderDisplayMode(); - this._updateDomImpl_updateCommands(); - }; - _CommandingSurface.prototype._updateDomImpl_renderDisplayMode = function () { - var rendered = this._updateDomImpl_renderedState; - if (rendered.isOpenedMode !== this._isOpenedMode) { - if (this._isOpenedMode) { - // Render opened - removeClass(this._dom.root, _Constants.ClassNames.closedClass); - addClass(this._dom.root, _Constants.ClassNames.openedClass); - } - else { - // Render closed - removeClass(this._dom.root, _Constants.ClassNames.openedClass); - addClass(this._dom.root, _Constants.ClassNames.closedClass); - } - rendered.isOpenedMode = this._isOpenedMode; - } - if (rendered.closedDisplayMode !== this.closedDisplayMode) { - removeClass(this._dom.root, closedDisplayModeClassMap[rendered.closedDisplayMode]); - addClass(this._dom.root, closedDisplayModeClassMap[this.closedDisplayMode]); - rendered.closedDisplayMode = this.closedDisplayMode; - } - if (rendered.overflowDirection !== this.overflowDirection) { - removeClass(this._dom.root, overflowDirectionClassMap[rendered.overflowDirection]); - addClass(this._dom.root, overflowDirectionClassMap[this.overflowDirection]); - rendered.overflowDirection = this.overflowDirection; - } - if (this._overflowAlignmentOffset !== rendered.overflowAlignmentOffset) { - var offsetProperty = (this._rtl ? "left" : "right"); - var offsetTextValue = this._overflowAlignmentOffset + "px"; - this._dom.overflowAreaContainer.style[offsetProperty] = offsetTextValue; - } - }; - _CommandingSurface.prototype._updateDomImpl_updateCommands = function () { - this._writeProfilerMark("_updateDomImpl_updateCommands,info"); - var nextStage = this._nextLayoutStage; - while (nextStage !== CommandLayoutPipeline.idle) { - var currentStage = nextStage; - var okToProceed = false; - switch (currentStage) { - case CommandLayoutPipeline.newDataStage: - nextStage = CommandLayoutPipeline.measuringStage; - okToProceed = this._processNewData(); - break; - case CommandLayoutPipeline.measuringStage: - nextStage = CommandLayoutPipeline.layoutStage; - okToProceed = this._measure(); - break; - case CommandLayoutPipeline.layoutStage: - nextStage = CommandLayoutPipeline.idle; - okToProceed = this._layoutCommands(); - break; - } - if (!okToProceed) { - // If a stage fails, exit the loop and track that stage - // to be restarted the next time _updateCommands is run. - nextStage = currentStage; - break; - } - } - this._nextLayoutStage = nextStage; - if (nextStage === CommandLayoutPipeline.idle) { - // Callback for unit tests. - this._layoutCompleteCallback && this._layoutCompleteCallback(); - } - }; - _CommandingSurface.prototype._getDataChangeInfo = function () { - var i = 0, len = 0; - var added = []; - var deleted = []; - var affected = []; - var currentShown = []; - var currentElements = []; - var newShown = []; - var newHidden = []; - var newElements = []; - Array.prototype.forEach.call(this._dom.actionArea.querySelectorAll(_Constants.commandSelector), function (commandElement) { - if (commandElement.style.display !== "none") { - currentShown.push(commandElement); - } - currentElements.push(commandElement); - }); - this.data.forEach(function (command) { - if (command.element.style.display !== "none") { - newShown.push(command.element); - } - else { - newHidden.push(command.element); - } - newElements.push(command.element); - }); - deleted = diffElements(currentShown, newShown); - affected = diffElements(currentShown, deleted); - // "added" must also include the elements from "newHidden" to ensure that we continue - // to animate any command elements that have underflowed back into the actionarea - // as a part of this data change. - added = diffElements(newShown, currentShown).concat(newHidden); - return { - newElements: newElements, - currentElements: currentElements, - added: added, - deleted: deleted, - affected: affected, - }; - }; - _CommandingSurface.prototype._processNewData = function () { - var _this = this; - this._writeProfilerMark("_processNewData,info"); - var changeInfo = this._getDataChangeInfo(); - // Take a snapshot of the current state - var updateCommandAnimation = Animations._createUpdateListAnimation(changeInfo.added, changeInfo.deleted, changeInfo.affected); - // Unbind property mutation event listener from deleted IObservableCommands - changeInfo.deleted.forEach(function (deletedElement) { - var command = (deletedElement['winControl']); - if (command && command['_propertyMutations']) { - command._propertyMutations.unbind(_this._refreshBound); - } - }); - // Bind property mutation event listener to added IObservable commands. - changeInfo.added.forEach(function (deletedElement) { - var command = (deletedElement['winControl']); - if (command && command['_propertyMutations']) { - command._propertyMutations.bind(_this._refreshBound); - } - }); - // Remove current ICommand elements - changeInfo.currentElements.forEach(function (element) { - if (element.parentElement) { - element.parentElement.removeChild(element); - } - }); - // Add new ICommand elements in the right order. - changeInfo.newElements.forEach(function (element) { - _this._dom.actionArea.appendChild(element); - }); - // Ensure that the overflow button is always the last element in the actionarea - this._dom.actionArea.appendChild(this._dom.overflowButton); - if (this.data.length > 0) { - _ElementUtilities.removeClass(this._dom.root, _Constants.ClassNames.emptyCommandingSurfaceCssClass); - } - else { - _ElementUtilities.addClass(this._dom.root, _Constants.ClassNames.emptyCommandingSurfaceCssClass); - } - // Execute the animation. - updateCommandAnimation.execute(); - // Indicate processing was successful. - return true; - }; - _CommandingSurface.prototype._measure = function () { - var _this = this; - this._writeProfilerMark("_measure,info"); - var canMeasure = (_Global.document.body.contains(this._dom.root) && this._dom.actionArea.offsetWidth > 0); - if (canMeasure) { - var overflowButtonWidth = _ElementUtilities._getPreciseTotalWidth(this._dom.overflowButton), actionAreaContentBoxWidth = _ElementUtilities._getPreciseContentWidth(this._dom.actionArea), separatorWidth = 0, standardCommandWidth = 0, contentCommandWidths = {}; - this._primaryCommands.forEach(function (command) { - // Ensure that the element we are measuring does not have display: none (e.g. it was just added, and it - // will be animated in) - var originalDisplayStyle = command.element.style.display; - command.element.style.display = ""; - if (command.type === _Constants.typeContent) { - // Measure each 'content' command type that we find - contentCommandWidths[_this._commandUniqueId(command)] = _ElementUtilities._getPreciseTotalWidth(command.element); - } - else if (command.type === _Constants.typeSeparator) { - // Measure the first 'separator' command type we find. - if (!separatorWidth) { - separatorWidth = _ElementUtilities._getPreciseTotalWidth(command.element); - } - } - else { - // Button, toggle, 'flyout' command types have the same width. Measure the first one we find. - if (!standardCommandWidth) { - standardCommandWidth = _ElementUtilities._getPreciseTotalWidth(command.element); - } - } - // Restore the original display style - command.element.style.display = originalDisplayStyle; - }); - this._cachedMeasurements = { - contentCommandWidths: contentCommandWidths, - separatorWidth: separatorWidth, - standardCommandWidth: standardCommandWidth, - overflowButtonWidth: overflowButtonWidth, - actionAreaContentBoxWidth: actionAreaContentBoxWidth, - }; - // Indicate measure was successful - return true; - } - else { - // Indicate measure was unsuccessful - return false; - } - }; - _CommandingSurface.prototype._layoutCommands = function () { - var _this = this; - this._writeProfilerMark("_layoutCommands,StartTM"); - // - // Filter commands that will not be visible in the actionarea - // - this._primaryCommands.forEach(function (command) { - command.element.style.display = (command.hidden ? "none" : ""); - }); - var primaryCommandsLocation = this._getVisiblePrimaryCommandsLocation(); - this._hideSeparatorsIfNeeded(primaryCommandsLocation.actionArea); - // Primary commands that will be mirrored in the overflow area should be hidden so - // that they are not visible in the actionarea. - primaryCommandsLocation.overflowArea.forEach(function (command) { - command.element.style.display = "none"; - }); - // The secondary commands in the actionarea should be hidden since they are always - // mirrored as new elements in the overflow area. - this._secondaryCommands.forEach(function (command) { - command.element.style.display = "none"; - }); - var overflowCommands = primaryCommandsLocation.overflowArea; - var showOverflowButton = (overflowCommands.length > 0 || this._secondaryCommands.length > 0); - this._dom.overflowButton.style.display = showOverflowButton ? "" : "none"; - // Set up a custom content flyout if there will be "content" typed commands in the overflowarea. - var isCustomContent = function (command) { - return command.type === _Constants.typeContent; - }; - var hasCustomContent = overflowCommands.some(isCustomContent) || this._secondaryCommands.some(isCustomContent); - if (hasCustomContent && !this._contentFlyout) { - this._contentFlyoutInterior = _Global.document.createElement("div"); - _ElementUtilities.addClass(this._contentFlyoutInterior, _Constants.ClassNames.contentFlyoutCssClass); - this._contentFlyout = new _Flyout.Flyout(); - this._contentFlyout.element.appendChild(this._contentFlyoutInterior); - _Global.document.body.appendChild(this._contentFlyout.element); - this._contentFlyout.onbeforeshow = function () { - _ElementUtilities.empty(_this._contentFlyoutInterior); - _ElementUtilities._reparentChildren(_this._chosenCommand.element, _this._contentFlyoutInterior); - }; - this._contentFlyout.onafterhide = function () { - _ElementUtilities._reparentChildren(_this._contentFlyoutInterior, _this._chosenCommand.element); - }; - } - // - // Project overflowing and secondary commands into the overflowArea as MenuCommands - // - // Clean up previous MenuCommand projections - _ElementUtilities.empty(this._dom.overflowArea); - this._menuCommandProjections.map(function (menuCommand) { - if (_this._contentFlyout && menuCommand.flyout === _this._contentFlyout) { - // Prevent our _contentFlyout from being disposed with the MenuCommand. - menuCommand.flyout = null; - } - menuCommand.dispose(); - }); - var hasToggleCommands = false, menuCommandProjections = []; - // Add primary commands that have overflowed. - overflowCommands.forEach(function (command) { - if (command.type === _Constants.typeToggle) { - hasToggleCommands = true; - } - menuCommandProjections.push(_this._projectAsMenuCommand(command)); - }); - // Add separator between primary and secondary command if applicable - var secondaryCommandsLength = this._secondaryCommands.length; - if (overflowCommands.length > 0 && secondaryCommandsLength > 0) { - var separator = new _CommandingSurfaceMenuCommand._MenuCommand(null, { - type: _Constants.typeSeparator - }); - menuCommandProjections.push(separator); - } - // Add secondary commands - this._secondaryCommands.forEach(function (command) { - if (!command.hidden) { - if (command.type === _Constants.typeToggle) { - hasToggleCommands = true; - } - menuCommandProjections.push(_this._projectAsMenuCommand(command)); - } - }); - this._hideSeparatorsIfNeeded(menuCommandProjections); - menuCommandProjections.forEach(function (command) { - _this._dom.overflowArea.appendChild(command.element); - }); - this._menuCommandProjections = menuCommandProjections; - _ElementUtilities[hasToggleCommands ? "addClass" : "removeClass"](this._dom.overflowArea, _Constants.ClassNames.menuContainsToggleCommandClass); - this._writeProfilerMark("_layoutCommands,StopTM"); - // Indicate layout was successful. - return true; - }; - _CommandingSurface.prototype._commandUniqueId = function (command) { - return _ElementUtilities._uniqueID(command.element); - }; - _CommandingSurface.prototype._getVisiblePrimaryCommandsInfo = function () { - var width = 0; - var commands = []; - var priority = 0; - var currentAssignedPriority = 0; - for (var i = this._primaryCommands.length - 1; i >= 0; i--) { - var command = this._primaryCommands[i]; - if (!command.hidden) { - if (command.priority === undefined) { - priority = currentAssignedPriority--; - } - else { - priority = command.priority; - } - width = (command.element.style.display === "none" ? 0 : this._getCommandWidth(command)); - commands.unshift({ - command: command, - width: width, - priority: priority - }); - } - } - return commands; - }; - _CommandingSurface.prototype._getVisiblePrimaryCommandsLocation = function () { - this._writeProfilerMark("_getVisiblePrimaryCommandsLocation,info"); - var actionAreaCommands = []; - var overflowAreaCommands = []; - var overflowButtonSpace = 0; - var hasSecondaryCommands = this._secondaryCommands.length > 0; - var commandsInfo = this._getVisiblePrimaryCommandsInfo(); - var sortedCommandsInfo = commandsInfo.slice(0).sort(function (commandInfo1, commandInfo2) { - return commandInfo1.priority - commandInfo2.priority; - }); - var maxPriority = Number.MAX_VALUE; - var availableWidth = this._cachedMeasurements.actionAreaContentBoxWidth; - for (var i = 0, len = sortedCommandsInfo.length; i < len; i++) { - availableWidth -= sortedCommandsInfo[i].width; - // The overflow button needs space if there are secondary commands, or we are not evaluating the last command. - overflowButtonSpace = (hasSecondaryCommands || (i < len - 1) ? this._cachedMeasurements.overflowButtonWidth : 0); - if (availableWidth - overflowButtonSpace < 0) { - maxPriority = sortedCommandsInfo[i].priority - 1; - break; - } - } - commandsInfo.forEach(function (commandInfo) { - if (commandInfo.priority <= maxPriority) { - actionAreaCommands.push(commandInfo.command); - } - else { - overflowAreaCommands.push(commandInfo.command); - } - }); - return { - actionArea: actionAreaCommands, - overflowArea: overflowAreaCommands - }; - }; - _CommandingSurface.prototype._getCommandWidth = function (command) { - if (command.type === _Constants.typeContent) { - return this._cachedMeasurements.contentCommandWidths[this._commandUniqueId(command)]; - } - else if (command.type === _Constants.typeSeparator) { - return this._cachedMeasurements.separatorWidth; - } - else { - return this._cachedMeasurements.standardCommandWidth; - } - }; - _CommandingSurface.prototype._projectAsMenuCommand = function (originalCommand) { - var _this = this; - var menuCommand = new _CommandingSurfaceMenuCommand._MenuCommand(null, { - label: originalCommand.label, - type: (originalCommand.type === _Constants.typeContent ? _Constants.typeFlyout : originalCommand.type) || _Constants.typeButton, - disabled: originalCommand.disabled, - flyout: originalCommand.flyout, - beforeInvoke: function () { - // Save the command that was selected - _this._chosenCommand = (menuCommand["_originalICommand"]); - // If this WinJS.UI.MenuCommand has type: toggle, we should also toggle the value of the original WinJS.UI.Command - if (_this._chosenCommand.type === _Constants.typeToggle) { - _this._chosenCommand.selected = !_this._chosenCommand.selected; - } - } - }); - if (originalCommand.selected) { - menuCommand.selected = true; - } - if (originalCommand.extraClass) { - menuCommand.extraClass = originalCommand.extraClass; - } - if (originalCommand.type === _Constants.typeContent) { - if (!menuCommand.label) { - menuCommand.label = _Constants.contentMenuCommandDefaultLabel; - } - menuCommand.flyout = this._contentFlyout; - } - else { - menuCommand.onclick = originalCommand.onclick; - } - menuCommand["_originalICommand"] = originalCommand; - return menuCommand; - }; - _CommandingSurface.prototype._hideSeparatorsIfNeeded = function (commands) { - var prevType = _Constants.typeSeparator; - var command; - // Hide all leading or consecutive separators - var commandsLength = commands.length; - commands.forEach(function (command) { - if (command.type === _Constants.typeSeparator && prevType === _Constants.typeSeparator) { - command.element.style.display = "none"; - } - prevType = command.type; - }); - for (var i = commandsLength - 1; i >= 0; i--) { - command = commands[i]; - if (command.type === _Constants.typeSeparator) { - command.element.style.display = "none"; - } - else { - break; - } - } - }; - _CommandingSurface.prototype._clearAnimation = function () { - var transformScriptName = _BaseUtils._browserStyleEquivalents["transform"].scriptName; - this._dom.actionAreaContainer.style[transformScriptName] = ""; - this._dom.actionArea.style[transformScriptName] = ""; - this._dom.overflowAreaContainer.style[transformScriptName] = ""; - this._dom.overflowArea.style[transformScriptName] = ""; - }; - /// Display options for the actionarea when the _CommandingSurface is closed. - _CommandingSurface.ClosedDisplayMode = ClosedDisplayMode; - /// Display options used by the _Commandingsurface to determine which direction it should expand when opening. - _CommandingSurface.OverflowDirection = OverflowDirection; - _CommandingSurface.supportedForProcessing = true; - return _CommandingSurface; - })(); - exports._CommandingSurface = _CommandingSurface; - _Base.Class.mix(_CommandingSurface, _Events.createEventProperties(_Constants.EventNames.beforeOpen, _Constants.EventNames.afterOpen, _Constants.EventNames.beforeClose, _Constants.EventNames.afterClose)); - // addEventListener, removeEventListener, dispatchEvent - _Base.Class.mix(_CommandingSurface, _Control.DOMEventMixin); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/CommandingSurface',["require", "exports"], function (require, exports) { - var module = null; - function getModule() { - if (!module) { - require(["./CommandingSurface/_CommandingSurface"], function (m) { - module = m; - }); - } - return module._CommandingSurface; - } - var publicMembers = Object.create({}, { - _CommandingSurface: { - get: function () { - return getModule(); - } - } - }); - return publicMembers; -}); - - -define('require-style!less/styles-toolbar',[],function(){}); -define('WinJS/Controls/ToolBar/_ToolBar',["require", "exports", "../../Core/_Base", "../ToolBar/_Constants", "../CommandingSurface", "../../Utilities/_Control", "../../Utilities/_Dispose", "../../Utilities/_ElementUtilities", "../../Core/_ErrorFromName", '../../Core/_Events', "../../Core/_Global", '../../_LightDismissService', "../../Core/_Resources", '../../Utilities/_OpenCloseMachine', "../../Core/_WriteProfilerMark"], function (require, exports, _Base, _Constants, _CommandingSurface, _Control, _Dispose, _ElementUtilities, _ErrorFromName, _Events, _Global, _LightDismissService, _Resources, _OpenCloseMachine, _WriteProfilerMark) { - require(["require-style!less/styles-toolbar"]); - "use strict"; - var strings = { - get ariaLabel() { - return _Resources._getWinJSString("ui/toolbarAriaLabel").value; - }, - get overflowButtonAriaLabel() { - return _Resources._getWinJSString("ui/toolbarOverflowButtonAriaLabel").value; - }, - get mustContainCommands() { - return "The toolbar can only contain WinJS.UI.Command or WinJS.UI.AppBarCommand controls"; - }, - get duplicateConstruction() { - return "Invalid argument: Controls may only be instantiated one time for each DOM element"; - } - }; - var ClosedDisplayMode = { - /// - /// When the ToolBar is closed, the height of the ToolBar is reduced such that button commands are still visible, but their labels are hidden. - /// - compact: "compact", - /// - /// When the ToolBar is closed, the height of the ToolBar is always sized to content. - /// - full: "full", - }; - var closedDisplayModeClassMap = {}; - closedDisplayModeClassMap[ClosedDisplayMode.compact] = _Constants.ClassNames.compactClass; - closedDisplayModeClassMap[ClosedDisplayMode.full] = _Constants.ClassNames.fullClass; - // Versions of add/removeClass that are no ops when called with falsy class names. - function addClass(element, className) { - className && _ElementUtilities.addClass(element, className); - } - function removeClass(element, className) { - className && _ElementUtilities.removeClass(element, className); - } - /// - /// - /// Displays ICommands within the flow of the app. Use the ToolBar around other statically positioned app content. - /// - /// - /// - /// - /// - /// - /// ]]> - /// The entire ToolBar control. - /// The toolbar overflow button. - /// The container for toolbar commands that overflow. - /// - /// - var ToolBar = (function () { - function ToolBar(element, options) { - /// - /// - /// Creates a new ToolBar control. - /// - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the new ToolBar control. - /// - /// - /// The new ToolBar control. - /// - /// - var _this = this; - if (options === void 0) { options = {}; } - // State private to the _updateDomImpl family of method. No other methods should make use of it. - // - // Nothing has been rendered yet so these are all initialized to undefined. Because - // they are undefined, the first time _updateDomImpl is called, they will all be - // rendered. - this._updateDomImpl_renderedState = { - isOpenedMode: undefined, - closedDisplayMode: undefined, - prevInlineWidth: undefined, - }; - this._writeProfilerMark("constructor,StartTM"); - // Check to make sure we weren't duplicated - if (element && element["winControl"]) { - throw new _ErrorFromName("WinJS.UI.ToolBar.DuplicateConstruction", strings.duplicateConstruction); - } - this._initializeDom(element || _Global.document.createElement("div")); - var stateMachine = new _OpenCloseMachine.OpenCloseMachine({ - eventElement: this.element, - onOpen: function () { - var openAnimation = _this._commandingSurface.createOpenAnimation(_this._getClosedHeight()); - _this._synchronousOpen(); - return openAnimation.execute(); - }, - onClose: function () { - var closeAnimation = _this._commandingSurface.createCloseAnimation(_this._getClosedHeight()); - return closeAnimation.execute().then(function () { - _this._synchronousClose(); - }); - }, - onUpdateDom: function () { - _this._updateDomImpl(); - }, - onUpdateDomWithIsOpened: function (isOpened) { - _this._isOpenedMode = isOpened; - _this._updateDomImpl(); - } - }); - // Events - this._handleShowingKeyboardBound = this._handleShowingKeyboard.bind(this); - _ElementUtilities._inputPaneListener.addEventListener(this._dom.root, "showing", this._handleShowingKeyboardBound); - // Initialize private state. - this._disposed = false; - this._cachedClosedHeight = null; - this._commandingSurface = new _CommandingSurface._CommandingSurface(this._dom.commandingSurfaceEl, { openCloseMachine: stateMachine }); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-actionarea"), _Constants.ClassNames.actionAreaCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-overflowarea"), _Constants.ClassNames.overflowAreaCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-overflowbutton"), _Constants.ClassNames.overflowButtonCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-ellipsis"), _Constants.ClassNames.ellipsisCssClass); - this._isOpenedMode = _Constants.defaultOpened; - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._dom.root, - tabIndex: this._dom.root.hasAttribute("tabIndex") ? this._dom.root.tabIndex : -1, - onLightDismiss: function () { - _this.close(); - } - }); - // Initialize public properties. - this.closedDisplayMode = _Constants.defaultClosedDisplayMode; - this.opened = this._isOpenedMode; - _Control.setOptions(this, options); - // Exit the Init state. - _ElementUtilities._inDom(this.element).then(function () { - return _this._commandingSurface.initialized; - }).then(function () { - stateMachine.exitInit(); - _this._writeProfilerMark("constructor,StopTM"); - }); - } - Object.defineProperty(ToolBar.prototype, "element", { - /// - get: function () { - return this._dom.root; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ToolBar.prototype, "data", { - /// - /// Gets or sets the Binding List of WinJS.UI.Command for the ToolBar. - /// - get: function () { - return this._commandingSurface.data; - }, - set: function (value) { - this._commandingSurface.data = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ToolBar.prototype, "closedDisplayMode", { - /// - /// Gets or sets the closedDisplayMode for the ToolBar. Values are "compact" and "full". - /// - get: function () { - return this._commandingSurface.closedDisplayMode; - }, - set: function (value) { - if (ClosedDisplayMode[value]) { - this._commandingSurface.closedDisplayMode = value; - this._cachedClosedHeight = null; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(ToolBar.prototype, "opened", { - /// - get: function () { - return this._commandingSurface.opened; - }, - set: function (value) { - this._commandingSurface.opened = value; - }, - enumerable: true, - configurable: true - }); - ToolBar.prototype.open = function () { - /// - /// - /// Opens the ToolBar - /// - /// - this._commandingSurface.open(); - }; - ToolBar.prototype.close = function () { - /// - /// - /// Closes the ToolBar - /// - /// - this._commandingSurface.close(); - }; - ToolBar.prototype.dispose = function () { - /// - /// - /// Disposes this ToolBar. - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - _LightDismissService.hidden(this._dismissable); - // Disposing the _commandingSurface will trigger dispose on its OpenCloseMachine and synchronously complete any animations that might have been running. - this._commandingSurface.dispose(); - // If page navigation is happening, we don't want the ToolBar left behind in the body. - // Synchronoulsy close the ToolBar to force it out of the body and back into its parent element. - this._synchronousClose(); - _ElementUtilities._inputPaneListener.removeEventListener(this._dom.root, "showing", this._handleShowingKeyboardBound); - _Dispose.disposeSubTree(this.element); - }; - ToolBar.prototype.forceLayout = function () { - /// - /// - /// Forces the ToolBar to update its layout. Use this function when the window did not change size, but the container of the ToolBar changed size. - /// - /// - this._commandingSurface.forceLayout(); - }; - ToolBar.prototype.getCommandById = function (id) { - /// - /// - /// Retrieves the command with the specified ID from this ToolBar. - /// If more than one command is found, this method returns the first command found. - /// - /// Id of the command to return. - /// - /// The command found, or null if no command is found. - /// - /// - return this._commandingSurface.getCommandById(id); - }; - ToolBar.prototype.showOnlyCommands = function (commands) { - /// - /// - /// Show the specified commands, hiding all of the others in the ToolBar. - /// - /// - /// An array of the commands to show. The array elements may be Command objects, or the string identifiers (IDs) of commands. - /// - /// - return this._commandingSurface.showOnlyCommands(commands); - }; - ToolBar.prototype._writeProfilerMark = function (text) { - _WriteProfilerMark("WinJS.UI.ToolBar:" + this._id + ":" + text); - }; - ToolBar.prototype._initializeDom = function (root) { - this._writeProfilerMark("_intializeDom,info"); - // Attaching JS control to DOM element - root["winControl"] = this; - this._id = root.id || _ElementUtilities._uniqueID(root); - _ElementUtilities.addClass(root, _Constants.ClassNames.controlCssClass); - _ElementUtilities.addClass(root, _Constants.ClassNames.disposableCssClass); - // Make sure we have an ARIA role - var role = root.getAttribute("role"); - if (!role) { - root.setAttribute("role", "menubar"); - } - var label = root.getAttribute("aria-label"); - if (!label) { - root.setAttribute("aria-label", strings.ariaLabel); - } - // Create element for commandingSurface and reparent any declarative Commands. - // The CommandingSurface constructor will parse child elements as AppBarCommands. - var commandingSurfaceEl = document.createElement("DIV"); - _ElementUtilities._reparentChildren(root, commandingSurfaceEl); - root.appendChild(commandingSurfaceEl); - // While the ToolBar is open, it will place itself in the so it can become a light dismissible - // overlay. It leaves the placeHolder element behind as stand in at the ToolBar's original DOM location - // to avoid reflowing surrounding app content and create the illusion that the ToolBar hasn't moved along - // the x or y planes. - var placeHolder = _Global.document.createElement("DIV"); - _ElementUtilities.addClass(placeHolder, _Constants.ClassNames.placeHolderCssClass); - // If the ToolBar's original HTML parent node is disposed while the ToolBar is open and repositioned as - // a temporary child of the , make sure that calling dispose on the placeHolder element will trigger - // dispose on the ToolBar as well. - _Dispose.markDisposable(placeHolder, this.dispose.bind(this)); - this._dom = { - root: root, - commandingSurfaceEl: commandingSurfaceEl, - placeHolder: placeHolder, - }; - }; - ToolBar.prototype._handleShowingKeyboard = function (event) { - // Because the ToolBar takes up layout space and is not an overlay, it doesn't have the same expectation - // to move itself to get out of the way of a showing IHM. Instsead we just close the ToolBar to avoid - // scenarios where the ToolBar is occluded, but the click-eating-div is still present since it may seem - // strange to end users that an occluded ToolBar (out of sight, out of mind) is still eating their first - // click. - // Mitigation: - // Because (1) custom content in a ToolBar can only be included as a 'content' type command, because (2) - // the ToolBar only supports closedDisplayModes 'compact' and 'full', and because (3) 'content' type - // commands in the overflowarea use a separate contentflyout to display their contents: - // Interactable custom content contained within the ToolBar actionarea or overflowarea, will remain - // visible and interactable even when showing the IHM closes the ToolBar. - this.close(); - }; - ToolBar.prototype._synchronousOpen = function () { - this._isOpenedMode = true; - this._updateDomImpl(); - }; - ToolBar.prototype._synchronousClose = function () { - this._isOpenedMode = false; - this._updateDomImpl(); - }; - ToolBar.prototype._updateDomImpl = function () { - var rendered = this._updateDomImpl_renderedState; - if (rendered.isOpenedMode !== this._isOpenedMode) { - if (this._isOpenedMode) { - this._updateDomImpl_renderOpened(); - } - else { - this._updateDomImpl_renderClosed(); - } - rendered.isOpenedMode = this._isOpenedMode; - } - if (rendered.closedDisplayMode !== this.closedDisplayMode) { - removeClass(this._dom.root, closedDisplayModeClassMap[rendered.closedDisplayMode]); - addClass(this._dom.root, closedDisplayModeClassMap[this.closedDisplayMode]); - rendered.closedDisplayMode = this.closedDisplayMode; - } - this._commandingSurface.updateDomImpl(); - }; - ToolBar.prototype._getClosedHeight = function () { - if (this._cachedClosedHeight === null) { - var wasOpen = this._isOpenedMode; - if (this._isOpenedMode) { - this._synchronousClose(); - } - this._cachedClosedHeight = this._commandingSurface.getBoundingRects().commandingSurface.height; - if (wasOpen) { - this._synchronousOpen(); - } - } - return this._cachedClosedHeight; - }; - ToolBar.prototype._updateDomImpl_renderOpened = function () { - var _this = this; - // Measure closed state. - this._updateDomImpl_renderedState.prevInlineWidth = this._dom.root.style.width; - var closedBorderBox = this._dom.root.getBoundingClientRect(); - var closedContentWidth = _ElementUtilities._getPreciseContentWidth(this._dom.root); - var closedContentHeight = _ElementUtilities._getPreciseContentHeight(this._dom.root); - var closedStyle = getComputedStyle(this._dom.root); - var closedPaddingTop = _ElementUtilities._convertToPrecisePixels(closedStyle.paddingTop); - var closedBorderTop = _ElementUtilities._convertToPrecisePixels(closedStyle.borderTopWidth); - var closedMargins = _ElementUtilities._getPreciseMargins(this._dom.root); - var closedContentBoxTop = closedBorderBox.top + closedBorderTop + closedPaddingTop; - var closedContentBoxBottom = closedContentBoxTop + closedContentHeight; - // Size our placeHolder. Set height and width to match borderbox of the closed ToolBar. - // Copy ToolBar margins to the placeholder. - var placeHolder = this._dom.placeHolder; - var placeHolderStyle = placeHolder.style; - placeHolderStyle.width = closedBorderBox.width + "px"; - placeHolderStyle.height = closedBorderBox.height + "px"; - placeHolderStyle.marginTop = closedMargins.top + "px"; - placeHolderStyle.marginRight = closedMargins.right + "px"; - placeHolderStyle.marginBottom = closedMargins.bottom + "px"; - placeHolderStyle.marginLeft = closedMargins.left + "px"; - _ElementUtilities._maintainFocus(function () { - // Move ToolBar element to the body in preparation of becoming a light dismissible. Leave an equal sized placeHolder element - // at our original DOM location to avoid reflowing surrounding app content. - _this._dom.root.parentElement.insertBefore(placeHolder, _this._dom.root); - _Global.document.body.appendChild(_this._dom.root); - // Position the ToolBar to completely cover the same region as the placeholder element. - _this._dom.root.style.width = closedContentWidth + "px"; - _this._dom.root.style.left = closedBorderBox.left - closedMargins.left + "px"; - // Determine which direction to expand the CommandingSurface elements when opened. The overflow area will be rendered at the corresponding edge of - // the ToolBar's content box, so we choose the direction that offers the most space between that edge and the corresponding edge of the viewport. - // This is to reduce the chance that the overflow area might clip through the edge of the viewport. - var topOfViewport = 0; - var bottomOfViewport = _Global.innerHeight; - var distanceFromTop = closedContentBoxTop - topOfViewport; - var distanceFromBottom = bottomOfViewport - closedContentBoxBottom; - if (distanceFromTop > distanceFromBottom) { - // CommandingSurface is going to expand updwards. - _this._commandingSurface.overflowDirection = _Constants.OverflowDirection.top; - // Position the bottom edge of the ToolBar marginbox over the bottom edge of the placeholder marginbox. - _this._dom.root.style.bottom = (bottomOfViewport - closedBorderBox.bottom) - closedMargins.bottom + "px"; - } - else { - // CommandingSurface is going to expand downwards. - _this._commandingSurface.overflowDirection = _Constants.OverflowDirection.bottom; - // Position the top edge of the ToolBar marginbox over the top edge of the placeholder marginbox. - _this._dom.root.style.top = (topOfViewport + closedBorderBox.top) - closedMargins.top + "px"; - } - // Render opened state - _ElementUtilities.addClass(_this._dom.root, _Constants.ClassNames.openedClass); - _ElementUtilities.removeClass(_this._dom.root, _Constants.ClassNames.closedClass); - }); - this._commandingSurface.synchronousOpen(); - _LightDismissService.shown(this._dismissable); // Call at the start of the open animation - }; - ToolBar.prototype._updateDomImpl_renderClosed = function () { - var _this = this; - _ElementUtilities._maintainFocus(function () { - if (_this._dom.placeHolder.parentElement) { - // Restore our placement in the DOM - var placeHolder = _this._dom.placeHolder; - placeHolder.parentElement.insertBefore(_this._dom.root, placeHolder); - placeHolder.parentElement.removeChild(placeHolder); - } - // Render Closed - _this._dom.root.style.top = ""; - _this._dom.root.style.right = ""; - _this._dom.root.style.bottom = ""; - _this._dom.root.style.left = ""; - _this._dom.root.style.width = _this._updateDomImpl_renderedState.prevInlineWidth; - _ElementUtilities.addClass(_this._dom.root, _Constants.ClassNames.closedClass); - _ElementUtilities.removeClass(_this._dom.root, _Constants.ClassNames.openedClass); - }); - this._commandingSurface.synchronousClose(); - _LightDismissService.hidden(this._dismissable); // Call after the close animation - }; - /// - /// Display options for the actionarea when the ToolBar is closed. - /// - ToolBar.ClosedDisplayMode = ClosedDisplayMode; - ToolBar.supportedForProcessing = true; - return ToolBar; - })(); - exports.ToolBar = ToolBar; - _Base.Class.mix(ToolBar, _Events.createEventProperties(_Constants.EventNames.beforeOpen, _Constants.EventNames.afterOpen, _Constants.EventNames.beforeClose, _Constants.EventNames.afterClose)); - // addEventListener, removeEventListener, dispatchEvent - _Base.Class.mix(ToolBar, _Control.DOMEventMixin); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/ToolBar',["require", "exports", '../Core/_Base'], function (require, exports, _Base) { - var module = null; - _Base.Namespace.define("WinJS.UI", { - ToolBar: { - get: function () { - if (!module) { - require(["./ToolBar/_ToolBar"], function (m) { - module = m; - }); - } - return module.ToolBar; - } - } - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/_LegacyAppBar/_Layouts',[ - 'exports', - '../../Animations/_TransitionAnimation', - '../../BindingList', - '../../Core/_BaseUtils', - '../../Core/_Global', - '../../Core/_Base', - '../../Core/_ErrorFromName', - '../../Core/_Resources', - '../../Core/_WriteProfilerMark', - '../../Controls/ToolBar', - '../../Controls/ToolBar/_Constants', - '../../Promise', - '../../Scheduler', - '../../Utilities/_Control', - '../../Utilities/_Dispose', - '../../Utilities/_ElementUtilities', - '../AppBar/_Command', - './_Constants' -], function appBarLayoutsInit(exports, _TransitionAnimation, BindingList, _BaseUtils, _Global, _Base, _ErrorFromName, _Resources, _WriteProfilerMark, ToolBar, _ToolBarConstants, Promise, Scheduler, _Control, _Dispose, _ElementUtilities, _Command, _Constants) { - "use strict"; - - // AppBar will use this when AppBar.layout property is set to "custom" - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - _AppBarBaseLayout: _Base.Namespace._lazy(function () { - var baseType = _Constants.appBarLayoutCustom; - - var strings = { - get nullCommand() { return "Invalid argument: command must not be null"; } - }; - - var _AppBarBaseLayout = _Base.Class.define(function _AppBarBaseLayout_ctor(appBarEl, options) { - this._disposed = false; - - options = options || {}; - _Control.setOptions(this, options); - - if (appBarEl) { - this.connect(appBarEl); - } - }, { - // Members - className: { - get: function _AppBarBaseLayout_get_className() { - return this._className; - }, - }, - type: { - get: function _AppBarBaseLayout_get_className() { - return this._type || baseType; - }, - }, - commandsInOrder: { - get: function _AppBarBaseLayout_get_commandsInOrder() { - // Get a DOM ordered collection of the AppBarCommand elements in the AppBar. - var commandElements = this.appBarEl.querySelectorAll("." + _Constants.appBarCommandClass); - - // Return an array of AppBarCommand objects. - return Array.prototype.map.call(commandElements, function (commandElement) { - return commandElement.winControl; - }); - } - }, - connect: function _AppBarBaseLayout_connect(appBarEl) { - if (this.className) { - _ElementUtilities.addClass(appBarEl, this.className); - } - this.appBarEl = appBarEl; - }, - disconnect: function _AppBarBaseLayout_disconnect() { - if (this.className) { - _ElementUtilities.removeClass(this.appBarEl, this.className); - } - this.appBarEl = null; - this.dispose(); - }, - layout: function _AppBarBaseLayout_layout(commands) { - // Append commands to the DOM. - var len = commands.length; - for (var i = 0; i < len; i++) { - var command = this.sanitizeCommand(commands[i]); - this.appBarEl.appendChild(command._element); - } - }, - showCommands: function _AppBarBaseLayout_showCommands(commands) { - // Use the default overlay showCommands implementation - this.appBarEl.winControl._showCommands(commands); - }, - showOnlyCommands: function _AppBarBaseLayout_showOnlyCommands(commands) { - // Use the default overlay _showOnlyCommands implementation - this.appBarEl.winControl._showOnlyCommands(commands); - }, - hideCommands: function _AppBarBaseLayout_hideCommands(commands) { - // Use the default overlay _hideCommands implementation - this.appBarEl.winControl._hideCommands(commands); - }, - sanitizeCommand: function _AppBarBaseLayout_sanitizeCommand(command) { - if (!command) { - throw new _ErrorFromName("WinJS.UI.AppBar.NullCommand", strings.nullCommand); - } - // See if it's a command already - command = command.winControl || command; - if (!command._element) { - // Not a command, so assume it is options for the command's constructor. - command = new _Command.AppBarCommand(null, command); - } - // If we were attached somewhere else, detach us - if (command._element.parentElement) { - command._element.parentElement.removeChild(command._element); - } - - return command; - }, - dispose: function _AppBarBaseLayout_dispose() { - this._disposed = true; - }, - disposeChildren: function _AppBarBaseLayout_disposeChildren() { - var appBarFirstDiv = this.appBarEl.querySelectorAll("." + _Constants.firstDivClass); - appBarFirstDiv = appBarFirstDiv.length >= 1 ? appBarFirstDiv[0] : null; - var appBarFinalDiv = this.appBarEl.querySelectorAll("." + _Constants.finalDivClass); - appBarFinalDiv = appBarFinalDiv.length >= 1 ? appBarFinalDiv[0] : null; - - var children = this.appBarEl.children; - var length = children.length; - for (var i = 0; i < length; i++) { - var element = children[i]; - if (element === appBarFirstDiv || element === appBarFinalDiv) { - continue; - } else { - _Dispose.disposeSubTree(element); - } - } - }, - handleKeyDown: function _AppBarBaseLayout_handleKeyDown() { - // NOP - }, - commandsUpdated: function _AppBarBaseLayout_commandsUpdated() { - // NOP - }, - beginAnimateCommands: function _AppBarBaseLayout_beginAnimateCommands() { - // The parameters are 3 mutually exclusive arrays of win-command elements contained in this Overlay. - // 1) showCommands[]: All of the HIDDEN win-command elements that ARE scheduled to show. - // 2) hideCommands[]: All of the VISIBLE win-command elements that ARE scheduled to hide. - // 3) otherVisibleCommands[]: All VISIBLE win-command elements that ARE NOT scheduled to hide. - - // NOP - }, - endAnimateCommands: function _AppBarBaseLayout_endAnimateCommands() { - // NOP - }, - scale: function _AppBarBaseLayout_scale() { - // NOP - }, - resize: function _AppBarBaseLayout_resize() { - // NOP - }, - positionChanging: function _AppBarBaseLayout_positionChanging(fromPosition, toPosition) { - // NOP - return Promise.wrap(); - }, - setFocusOnShow: function _AppBarBaseLayout_setFocusOnShow() { - this.appBarEl.winControl._setFocusToAppBar(); - } - }); - return _AppBarBaseLayout; - }), - }); - - // AppBar will use this when AppBar.layout property is set to "commands" - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - _AppBarCommandsLayout: _Base.Namespace._lazy(function () { - var layoutClassName = _Constants.commandLayoutClass; - var layoutType = _Constants.appBarLayoutCommands; - - var _AppBarCommandsLayout = _Base.Class.derive(exports._AppBarBaseLayout, function _AppBarCommandsLayout_ctor(appBarEl) { - exports._AppBarBaseLayout.call(this, appBarEl, { _className: layoutClassName, _type: layoutType }); - this._commandLayoutsInit(appBarEl); - }, { - commandsInOrder: { - get: function _AppBarCommandsLayout_get_commandsInOrder() { - return this._originalCommands.filter(function (command) { - // Make sure the element is still in the AppBar. - return this.appBarEl.contains(command.element); - }, this); - } - }, - layout: function _AppBarCommandsLayout_layout(commands) { - // Insert commands and other layout specific DOM into the AppBar element. - - // Empty our tree. - _ElementUtilities.empty(this._primaryCommands); - _ElementUtilities.empty(this._secondaryCommands); - - // Keep track of the order we receive the commands in. - this._originalCommands = []; - - // Layout commands - for (var i = 0, len = commands.length; i < len; i++) { - var command = this.sanitizeCommand(commands[i]); - - this._originalCommands.push(command); - - if ("primary" === command.section || "global" === command.section) { - this._primaryCommands.appendChild(command._element); - } else { - this._secondaryCommands.appendChild(command._element); - } - } - - // Append layout containers to AppBar element. - // Secondary Commands should come first in Tab Order. - this.appBarEl.appendChild(this._secondaryCommands); - this.appBarEl.appendChild(this._primaryCommands); - - - // Need to measure all content commands after they have been added to the AppBar to make sure we allow - // user defined CSS rules based on the ancestor of the content command to take affect. - this._needToMeasureNewCommands = true; - - // In case this is called from the constructor before the AppBar element has been appended to the DOM, - // we schedule the initial scaling of commands, with the expectation that the element will be added - // synchronously, in the same block of code that called the constructor. - Scheduler.schedule(function () { - if (this._needToMeasureNewCommands && !this._disposed) { - this.scale(); - } - }.bind(this), Scheduler.Priority.idle, this, "WinJS._commandLayoutsMixin._scaleNewCommands"); - - }, - disposeChildren: function _AppBarCommandsLayout_disposeChildren() { - _Dispose.disposeSubTree(this._primaryCommands); - _Dispose.disposeSubTree(this._secondaryCommands); - }, - handleKeyDown: function _AppBarCommandsLayout_handleKeyDown(event) { - var Key = _ElementUtilities.Key; - - if (_ElementUtilities._matchesSelector(event.target, ".win-interactive, .win-interactive *")) { - return; // Ignore left, right, home & end keys if focused element has win-interactive class. - } - var rtl = _Global.getComputedStyle(this.appBarEl).direction === "rtl"; - var leftKey = rtl ? Key.rightArrow : Key.leftArrow; - var rightKey = rtl ? Key.leftArrow : Key.rightArrow; - - if (event.keyCode === leftKey || event.keyCode === rightKey || event.keyCode === Key.home || event.keyCode === Key.end) { - - var globalCommandHasFocus = this._primaryCommands.contains(_Global.document.activeElement); - var focusableCommands = this._getFocusableCommandsInLogicalOrder(globalCommandHasFocus); - var targetCommand; - - if (focusableCommands.length) { - switch (event.keyCode) { - case leftKey: - // Arrowing past the last command wraps back around to the first command. - var index = Math.max(-1, focusableCommands.focusedIndex - 1) + focusableCommands.length; - targetCommand = focusableCommands[index % focusableCommands.length].winControl.lastElementFocus; - break; - - case rightKey: - // Arrowing previous to the first command wraps back around to the last command. - var index = focusableCommands.focusedIndex + 1 + focusableCommands.length; - targetCommand = focusableCommands[index % focusableCommands.length].winControl.firstElementFocus; - break; - - case Key.home: - var index = 0; - targetCommand = focusableCommands[index].winControl.firstElementFocus; - break; - - case Key.end: - var index = focusableCommands.length - 1; - targetCommand = focusableCommands[index].winControl.lastElementFocus; - break; - } - } - - if (targetCommand && targetCommand !== _Global.document.activeElement) { - targetCommand.focus(); - // Prevent default so that the browser doesn't also evaluate the keydown event on the newly focused element. - event.preventDefault(); - } - } - }, - commandsUpdated: function _AppBarCommandsLayout_commandsUpdated(newSetOfVisibleCommands) { - // Whenever new commands are set or existing commands are hiding/showing in the AppBar, this - // function is called to update the cached width measurement of all visible AppBarCommands. - - var visibleCommands = (newSetOfVisibleCommands) ? newSetOfVisibleCommands : this.commandsInOrder.filter(function (command) { - return !command.hidden; - }); - this._fullSizeWidthOfLastKnownVisibleCommands = this._getWidthOfFullSizeCommands(visibleCommands); - }, - beginAnimateCommands: function _AppBarCommandsLayout_beginAnimateCommands(showCommands, hideCommands, otherVisibleCommands) { - // The parameters are 3 mutually exclusive arrays of win-command elements contained in this Overlay. - // 1) showCommands[]: All of the HIDDEN win-command elements that ARE scheduled to show. - // 2) hideCommands[]: All of the VISIBLE win-command elements that ARE scheduled to hide. - // 3) otherVisibleCommands[]: All VISIBLE win-command elements that ARE NOT scheduled to hide. - - this._scaleAfterAnimations = false; - - // Determine if the overall width of visible commands in the primary row will be increasing OR decreasing. - var changeInWidth = this._getWidthOfFullSizeCommands(showCommands) - this._getWidthOfFullSizeCommands(hideCommands); - if (changeInWidth > 0) { - // Width of contents is going to increase, update our command counts now, to what they will be after we complete the animations. - var visibleCommandsAfterAnimations = otherVisibleCommands.concat(showCommands); - this.commandsUpdated(visibleCommandsAfterAnimations); - // Make sure we will have enough room to fit everything on a single row. - this.scale(); - } else if (changeInWidth < 0) { - // Width of contents is going to decrease. Once animations are complete, check if - // there is enough available space to make the remaining commands full size. - this._scaleAfterAnimations = true; - } - }, - endAnimateCommands: function _AppBarCommandsLayout_endAnimateCommands() { - if (this._scaleAfterAnimations) { - this.commandsUpdated(); - this.scale(); - } - }, - resize: function _AppBarCommandsLayout_resize() { - if (!this._disposed) { - // Check for horizontal window resizes. - this._appBarTotalKnownWidth = null; - if (this.appBarEl.winControl.opened) { - this.scale(); - } - } - }, - disconnect: function _AppBarCommandsLayout_disconnect() { - exports._AppBarBaseLayout.prototype.disconnect.call(this); - }, - _getWidthOfFullSizeCommands: function _AppBarCommandsLayout_getWidthOfFullSizeCommands(commands) { - // Commands layout puts primary commands and secondary commands into the primary row. - // Return the total width of all visible primary and secondary commands as if they were full-size. - - // Perform any pending measurements on "content" type AppBarCommands. - if (this._needToMeasureNewCommands) { - this._measureContentCommands(); - } - var accumulatedWidth = 0; - var separatorsCount = 0; - var buttonsCount = 0; - - if (!commands) { - // Return the cached full size width of the last known visible commands in the AppBar. - return this._fullSizeWidthOfLastKnownVisibleCommands; - } else { - // Return the width of the specified commands. - var command; - for (var i = 0, len = commands.length; i < len; i++) { - command = commands[i].winControl || commands[i]; - if (command._type === _Constants.typeSeparator) { - separatorsCount++; - } else if (command._type !== _Constants.typeContent) { - // button, toggle, and flyout types all have the same width. - buttonsCount++; - } else { - accumulatedWidth += command._fullSizeWidth; - } - } - } - return accumulatedWidth += (separatorsCount * _Constants.separatorWidth) + (buttonsCount * _Constants.buttonWidth); - }, - _getFocusableCommandsInLogicalOrder: function _AppBarCommandsLayout_getCommandsInLogicalOrder() { - // Function returns an array of all the contained AppBarCommands which are reachable by left/right arrows. - - var secondaryCommands = this._secondaryCommands.children, - primaryCommands = this._primaryCommands.children, - focusedIndex = -1; - - var getFocusableCommandsHelper = function (commandsInReach) { - var focusableCommands = []; - for (var i = 0, len = commandsInReach.length; i < len; i++) { - var element = commandsInReach[i]; - if (_ElementUtilities.hasClass(element, _Constants.appBarCommandClass) && element.winControl) { - var containsFocus = element.contains(_Global.document.activeElement); - // With the inclusion of content type commands, it may be possible to tab to elements in AppBarCommands that are not reachable by arrow keys. - // Regardless, when an AppBarCommand contains the element with focus, we just include the whole command so that we can determine which - // commands are adjacent to it when looking for the next focus destination. - if (element.winControl._isFocusable() || containsFocus) { - focusableCommands.push(element); - if (containsFocus) { - focusedIndex = focusableCommands.length - 1; - } - } - } - } - return focusableCommands; - }; - - // Determines which set of commands the user could potentially reach through Home, End, and arrow keys. - // All commands in the commands layout AppBar, from left to right are in reach. Secondary (previously known as Selection) - // then Primary (previously known as Global). - var commandsInReach = Array.prototype.slice.call(secondaryCommands).concat(Array.prototype.slice.call(primaryCommands)); - - var focusableCommands = getFocusableCommandsHelper(commandsInReach); - focusableCommands.focusedIndex = focusedIndex; - return focusableCommands; - }, - _commandLayoutsInit: function _AppBarCommandsLayout_commandLayoutsInit() { - // Create layout infrastructure - this._primaryCommands = _Global.document.createElement("DIV"); - this._secondaryCommands = _Global.document.createElement("DIV"); - _ElementUtilities.addClass(this._primaryCommands, _Constants.primaryCommandsClass); - _ElementUtilities.addClass(this._secondaryCommands, _Constants.secondaryCommandsClass); - }, - _scaleHelper: function _AppBarCommandsLayout_scaleHelper() { - // This exists as a single line function so that unit tests can - // overwrite it since they can't resize the WWA window. - - // It is expected that AppBar is an immediate child of the and will have 100% width. - // We measure the clientWidth of the documentElement so that we can scale the AppBar lazily - // even while its element is display: 'none' - var extraPadding = this.appBarEl.winControl.closedDisplayMode === "minimal" ? _Constants.appBarInvokeButtonWidth : 0; - return _Global.document.documentElement.clientWidth - extraPadding; - }, - _measureContentCommands: function _AppBarCommandsLayout_measureContentCommands() { - // AppBar measures the width of content commands when they are first added - // and then caches that value to avoid additional layouts in the future. - - // Can't measure unless We're in the document body - if (_Global.document.body.contains(this.appBarEl)) { - this._needToMeasureNewCommands = false; - - var hadHiddenClass = _ElementUtilities.hasClass(this.appBarEl, "win-navbar-closed"); - _ElementUtilities.removeClass(this.appBarEl, "win-navbar-closed"); - - // Make sure AppBar and children have width dimensions. - var prevAppBarDisplay = this.appBarEl.style.display; - this.appBarEl.style.display = ""; - var prevCommandDisplay; - - var contentElements = this.appBarEl.querySelectorAll("div." + _Constants.appBarCommandClass); - var element; - for (var i = 0, len = contentElements.length; i < len; i++) { - element = contentElements[i]; - if (element.winControl && element.winControl._type === _Constants.typeContent) { - // Make sure command has width dimensions before we measure. - prevCommandDisplay = element.style.display; - element.style.display = ""; - element.winControl._fullSizeWidth = _ElementUtilities.getTotalWidth(element) || 0; - element.style.display = prevCommandDisplay; - } - } - - // Restore state to AppBar. - this.appBarEl.style.display = prevAppBarDisplay; - if (hadHiddenClass) { - _ElementUtilities.addClass(this.appBarEl, "win-navbar-closed"); - } - - this.commandsUpdated(); - } - }, - }); - return _AppBarCommandsLayout; - }), - }); - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - _AppBarMenuLayout: _Base.Namespace._lazy(function () { - var layoutClassName = _Constants.menuLayoutClass; - var layoutType = _Constants.appBarLayoutMenu; - - // - // Resize animation - // The resize animation requires 2 animations to run simultaneously in sync with each other. It's implemented - // without PVL because PVL doesn't provide a way to guarantee that 2 animations will start at the same time. - // - var transformNames = _BaseUtils._browserStyleEquivalents["transform"]; - function transformWithTransition(element, transition) { - // transition's properties: - // - duration: Number representing the duration of the animation in milliseconds. - // - timing: String representing the CSS timing function that controls the progress of the animation. - // - to: The value of *element*'s transform property after the animation. - var duration = transition.duration * _TransitionAnimation._animationFactor; - var transitionProperty = _BaseUtils._browserStyleEquivalents["transition"].scriptName; - element.style[transitionProperty] = duration + "ms " + transformNames.cssName + " " + transition.timing; - element.style[transformNames.scriptName] = transition.to; - - var finish; - return new Promise(function (c) { - var onTransitionEnd = function (eventObject) { - if (eventObject.target === element && eventObject.propertyName === transformNames.cssName) { - finish(); - } - }; - - var didFinish = false; - finish = function () { - if (!didFinish) { - _Global.clearTimeout(timeoutId); - element.removeEventListener(_BaseUtils._browserEventEquivalents["transitionEnd"], onTransitionEnd); - element.style[transitionProperty] = ""; - didFinish = true; - } - c(); - }; - - // Watch dog timeout - var timeoutId = _Global.setTimeout(function () { - timeoutId = _Global.setTimeout(finish, duration); - }, 50); - - element.addEventListener(_BaseUtils._browserEventEquivalents["transitionEnd"], onTransitionEnd); - }, function () { - finish(); // On cancelation, complete the promise successfully to match PVL - }); - } - // See resizeTransition's comment for documentation on *args*. - function growTransition(elementClipper, element, args) { - var diff = args.anchorTrailingEdge ? args.to.total - args.from.total : args.from.total - args.to.total; - var translate = args.dimension === "width" ? "translateX" : "translateY"; - var size = args.dimension; - var duration = args.duration || 367; - var timing = args.timing || "cubic-bezier(0.1, 0.9, 0.2, 1)"; - - // Set up - elementClipper.style[size] = args.to.total + "px"; - elementClipper.style[transformNames.scriptName] = translate + "(" + diff + "px)"; - element.style[size] = args.to.content + "px"; - element.style[transformNames.scriptName] = translate + "(" + -diff + "px)"; - - // Resolve styles - _Global.getComputedStyle(elementClipper).opacity; - _Global.getComputedStyle(element).opacity; - - // Animate - var transition = { - duration: duration, - timing: timing, - to: "" - }; - return Promise.join([ - transformWithTransition(elementClipper, transition), - transformWithTransition(element, transition) - ]); - } - // See resizeTransition's comment for documentation on *args*. - function shrinkTransition(elementClipper, element, args) { - var diff = args.anchorTrailingEdge ? args.from.total - args.to.total : args.to.total - args.from.total; - var translate = args.dimension === "width" ? "translateX" : "translateY"; - var duration = args.duration || 367; - var timing = args.timing || "cubic-bezier(0.1, 0.9, 0.2, 1)"; - - // Set up - elementClipper.style[transformNames.scriptName] = ""; - element.style[transformNames.scriptName] = ""; - - // Resolve styles - _Global.getComputedStyle(elementClipper).opacity; - _Global.getComputedStyle(element).opacity; - - // Animate - var transition = { - duration: duration, - timing: timing - }; - var clipperTransition = _BaseUtils._merge(transition, { to: translate + "(" + diff + "px)" }); - var elementTransition = _BaseUtils._merge(transition, { to: translate + "(" + -diff + "px)" }); - return Promise.join([ - transformWithTransition(elementClipper, clipperTransition), - transformWithTransition(element, elementTransition) - ]); - } - // Plays an animation which makes an element look like it is resizing in 1 dimension. Arguments: - // - elementClipper: The parent of *element*. It shouldn't have any margin, border, or padding and its - // size should match element's size. Its purpose is to clip *element* during the animation to give - // it the illusion that it is resizing. - // - element: The element that should look like it's resizing. - // - args: An object with the following required properties: - // - from: An object representing the old width/height of the element. - // - to: An object representing the new width/height of the element. - // from/to are objects of the form { content: number; total: number; }. "content" is the - // width/height of *element*'s content box (e.g. getContentWidth). "total" is the width/height - // of *element*'s margin box (e.g. getTotalWidth). - // - duration: The CSS transition duration property. - // - timing: The CSS transition timing property. - // - dimension: The dimension on which *element* is resizing. Either "width" or "height". - // - anchorTrailingEdge: During the resize animation, one edge will move and the other edge will - // remain where it is. This flag specifies which edge is anchored (i.e. won't move). - // - function resizeTransition(elementClipper, element, args) { - if (args.to.total > args.from.total) { - return growTransition(elementClipper, element, args); - } else if (args.to.total < args.from.total) { - return shrinkTransition(elementClipper, element, args); - } else { - return Promise.as(); - } - } - - var _AppBarMenuLayout = _Base.Class.derive(exports._AppBarBaseLayout, function _AppBarMenuLayout_ctor(appBarEl) { - exports._AppBarBaseLayout.call(this, appBarEl, { _className: layoutClassName, _type: layoutType }); - this._tranformNames = _BaseUtils._browserStyleEquivalents["transform"]; - this._animationCompleteBound = this._animationComplete.bind(this); - this._positionToolBarBound = this._positionToolBar.bind(this); - }, { - commandsInOrder: { - get: function _AppBarMenuLayout_get_commandsInOrder() { - return this._originalCommands; - } - }, - layout: function _AppBarMenuLayout_layout(commands) { - this._writeProfilerMark("layout,info"); - - commands = commands || []; - this._originalCommands = []; - - var that = this; - commands.forEach(function (command) { - that._originalCommands.push(that.sanitizeCommand(command)); - }); - this._displayedCommands = this._originalCommands.slice(0); - - if (this._menu) { - _ElementUtilities.empty(this._menu); - } else { - this._menu = _Global.document.createElement("div"); - _ElementUtilities.addClass(this._menu, _Constants.menuContainerClass); - } - this.appBarEl.appendChild(this._menu); - - this._toolbarEl = _Global.document.createElement("div"); - this._menu.appendChild(this._toolbarEl); - - this._createToolBar(commands); - }, - - showCommands: function _AppBarMenuLayout_showCommands(commands) { - var elements = this._getCommandsElements(commands); - var data = []; - var newDisplayedCommands = []; - var that = this; - this._originalCommands.forEach(function (command) { - if (elements.indexOf(command.element) >= 0 || that._displayedCommands.indexOf(command) >= 0) { - newDisplayedCommands.push(command); - data.push(command); - } - }); - this._displayedCommands = newDisplayedCommands; - this._updateData(data); - }, - - showOnlyCommands: function _AppBarMenuLayout_showOnlyCommands(commands) { - this._displayedCommands = []; - this.showCommands(commands); - }, - - hideCommands: function _AppBarMenuLayout_hideCommands(commands) { - var elements = this._getCommandsElements(commands); - var data = []; - var newDisplayedCommands = []; - var that = this; - this._originalCommands.forEach(function (command) { - if (elements.indexOf(command.element) === -1 && that._displayedCommands.indexOf(command) >= 0) { - newDisplayedCommands.push(command); - data.push(command); - } - }); - this._displayedCommands = newDisplayedCommands; - this._updateData(data); - }, - - connect: function _AppBarMenuLayout_connect(appBarEl) { - this._writeProfilerMark("connect,info"); - - exports._AppBarBaseLayout.prototype.connect.call(this, appBarEl); - this._id = _ElementUtilities._uniqueID(appBarEl); - }, - - resize: function _AppBarMenuLayout_resize() { - this._writeProfilerMark("resize,info"); - - if (this._initialized) { - this._forceLayoutPending = true; - } - }, - - positionChanging: function _AppBarMenuLayout_positionChanging(fromPosition, toPosition) { - this._writeProfilerMark("positionChanging from:" + fromPosition + " to: " + toPosition + ",info"); - - this._animationPromise = this._animationPromise || Promise.wrap(); - - if (this._animating) { - this._animationPromise.cancel(); - } - - this._animating = true; - if (toPosition === "shown" || (fromPosition !== "shown" && toPosition === "compact")) { - this._positionToolBar(); - this._animationPromise = this._animateToolBarEntrance(); - } else { - if (fromPosition === "minimal" || fromPosition === "compact" || fromPosition === "hidden") { - this._animationPromise = Promise.wrap(); - } else { - this._animationPromise = this._animateToolBarExit(); - } - } - this._animationPromise.then(this._animationCompleteBound, this._animationCompleteBound); - return this._animationPromise; - }, - - disposeChildren: function _AppBarMenuLayout_disposeChildren() { - this._writeProfilerMark("disposeChildren,info"); - - if (this._toolbar) { - _Dispose.disposeSubTree(this._toolbarEl); - } - this._originalCommands = []; - this._displayedCommands = []; - }, - - setFocusOnShow: function _AppBarMenuLayout_setFocusOnShow() { - // Make sure the menu (used for clipping during the resize animation) - // doesn't scroll when we give focus to the AppBar. - this.appBarEl.winControl._setFocusToAppBar(true, this._menu); - }, - - _updateData: function _AppBarMenuLayout_updateData(data) { - var hadHiddenClass = _ElementUtilities.hasClass(this.appBarEl, "win-navbar-closed"); - var hadShownClass = _ElementUtilities.hasClass(this.appBarEl, "win-navbar-opened"); - _ElementUtilities.removeClass(this.appBarEl, "win-navbar-closed"); - - // Make sure AppBar and children have width dimensions. - var prevAppBarDisplay = this.appBarEl.style.display; - this.appBarEl.style.display = ""; - - - this._toolbar.data = new BindingList.List(data); - if (hadHiddenClass) { - this._positionToolBar(); - } - - // Restore state to AppBar. - this.appBarEl.style.display = prevAppBarDisplay; - if (hadHiddenClass) { - _ElementUtilities.addClass(this.appBarEl, "win-navbar-closed"); - } - - if (hadShownClass) { - this._positionToolBar(); - this._animateToolBarEntrance(); - } - }, - - _getCommandsElements: function _AppBarMenuLayout_getCommandsElements(commands) { - if (!commands) { - return []; - } - - if (typeof commands === "string" || !commands || !commands.length) { - commands = [commands]; - } - - var elements = []; - for (var i = 0, len = commands.length; i < len; i++) { - if (commands[i]) { - if (typeof commands[i] === "string") { - var element = _Global.document.getElementById(commands[i]); - if (element) { - elements.push(element); - } else { - // Check in the list we are tracking, since it might not be in the DOM yet - for (var j = 0, len2 = this._originalCommands.length; j < len2; j++) { - var element = this._originalCommands[j].element; - if (element.id === commands[i]) { - elements.push(element); - } - } - } - } else if (commands[i].element) { - elements.push(commands[i].element); - } else { - elements.push(commands[i]); - } - } - } - - return elements; - }, - - _animationComplete: function _AppBarMenuLayout_animationComplete() { - if (!this._disposed) { - this._animating = false; - } - }, - - _createToolBar: function _AppBarMenuLayout_createToolBar(commands) { - this._writeProfilerMark("_createToolBar,info"); - - var hadHiddenClass = _ElementUtilities.hasClass(this.appBarEl, "win-navbar-closed"); - _ElementUtilities.removeClass(this.appBarEl, "win-navbar-closed"); - - // Make sure AppBar and children have width dimensions. - var prevAppBarDisplay = this.appBarEl.style.display; - this.appBarEl.style.display = ""; - - this._toolbar = new ToolBar.ToolBar(this._toolbarEl, { - data: new BindingList.List(this._originalCommands), - shownDisplayMode: 'full', - }); - - var that = this; - this._appbarInvokeButton = this.appBarEl.querySelector("." + _Constants.invokeButtonClass); - this._overflowButton = this._toolbarEl.querySelector("." + _ToolBarConstants.overflowButtonCssClass); - this._overflowButton.addEventListener("click", function () { - that._appbarInvokeButton.click(); - }); - - this._positionToolBar(); - - // Restore state to AppBar. - this.appBarEl.style.display = prevAppBarDisplay; - if (hadHiddenClass) { - _ElementUtilities.addClass(this.appBarEl, "win-navbar-closed"); - } - }, - - _positionToolBar: function _AppBarMenuLayout_positionToolBar() { - if (!this._disposed) { - this._writeProfilerMark("_positionToolBar,info"); - this._initialized = true; - } - }, - - _animateToolBarEntrance: function _AppBarMenuLayout_animateToolBarEntrance() { - this._writeProfilerMark("_animateToolBarEntrance,info"); - - if (this._forceLayoutPending) { - this._forceLayoutPending = false; - this._toolbar.forceLayout(); - this._positionToolBar(); - } - var heightVisible = this._isMinimal() ? 0 : this.appBarEl.offsetHeight; - if (this._isBottom()) { - // Bottom AppBar Animation - var offsetTop = this._menu.offsetHeight - heightVisible; - return this._executeTranslate(this._menu, "translateY(" + -offsetTop + "px)"); - } else { - // Top AppBar Animation - return resizeTransition(this._menu, this._toolbarEl, { - from: { content: heightVisible, total: heightVisible }, - to: { content: this._menu.offsetHeight, total: this._menu.offsetHeight }, - dimension: "height", - duration: 400, - timing: "ease-in", - }); - } - }, - - _animateToolBarExit: function _AppBarMenuLayout_animateToolBarExit() { - this._writeProfilerMark("_animateToolBarExit,info"); - - var heightVisible = this._isMinimal() ? 0 : this.appBarEl.offsetHeight; - if (this._isBottom()) { - return this._executeTranslate(this._menu, "none"); - } else { - // Top AppBar Animation - return resizeTransition(this._menu, this._toolbarEl, { - from: { content: this._menu.offsetHeight, total: this._menu.offsetHeight }, - to: { content: heightVisible, total: heightVisible }, - dimension: "height", - duration: 400, - timing: "ease-in", - }); - } - }, - - _executeTranslate: function _AppBarMenuLayout_executeTranslate(element, value) { - return _TransitionAnimation.executeTransition(element, - { - property: this._tranformNames.cssName, - delay: 0, - duration: 400, - timing: "ease-in", - to: value - }); - }, - - _isMinimal: function _AppBarMenuLayout_isMinimal() { - return this.appBarEl.winControl.closedDisplayMode === "minimal"; - }, - - _isBottom: function _AppBarMenuLayout_isBottom() { - return this.appBarEl.winControl.placement === "bottom"; - }, - - _writeProfilerMark: function _AppBarMenuLayout_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI._AppBarMenuLayout:" + this._id + ":" + text); - } - }); - - return _AppBarMenuLayout; - }), - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// _LegacyAppBar -/// appbar,appBars,Flyout,Flyouts,iframe,Statics,unfocus,WinJS -define('WinJS/Controls/_LegacyAppBar',[ - 'exports', - '../Core/_Global', - '../Core/_WinRT', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Events', - '../Core/_Resources', - '../Core/_WriteProfilerMark', - '../Animations', - '../Promise', - '../Scheduler', - '../_LightDismissService', - '../Utilities/_Control', - '../Utilities/_Dispose', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - '../Utilities/_KeyboardBehavior', - './_LegacyAppBar/_Constants', - './_LegacyAppBar/_Layouts', - './AppBar/_Command', - './AppBar/_Icon', - './Flyout/_Overlay', - '../Application' -], function appBarInit(exports, _Global, _WinRT, _Base, _BaseUtils, _ErrorFromName, _Events, _Resources, _WriteProfilerMark, Animations, Promise, Scheduler, _LightDismissService, _Control, _Dispose, _ElementUtilities, _Hoverable, _KeyboardBehavior, _Constants, _Layouts, _Command, _Icon, _Overlay, Application) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// Represents an application toolbar for display commands. - /// - /// - /// - /// - /// - /// - /// ]]> - /// Raised just before showing the _LegacyAppBar. - /// Raised immediately after the _LegacyAppBar is fully shown. - /// Raised just before hiding the _LegacyAppBar. - /// Raised immediately after the _LegacyAppBar is fully hidden. - /// The _LegacyAppBar control itself. - /// Style for a custom layout _LegacyAppBar. - /// - /// - _LegacyAppBar: _Base.Namespace._lazy(function () { - var EVENTS = { - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose", - }; - - var createEvent = _Events._createEventProperty; - - // Enum of known constant pixel values for display modes. - var knownVisibleHeights = { - none: 0, - hidden: 0, - minimal: 25, - compact: 48 - }; - - // Maps each notion of a display modes to the corresponding visible position - var displayModeVisiblePositions = { - none: "hidden", - hidden: "hidden", - minimal: "minimal", - shown: "shown", - compact: "compact" - }; - - // Enum of closedDisplayMode constants - var closedDisplayModes = { - none: "none", - minimal: "minimal", - compact: "compact" - }; - - // Constants shown/hidden states - var appbarShownState = "shown", - appbarHiddenState = "hidden"; - - // Hook into event - var globalEventsInitialized = false; - - function _allManipulationChanged(event) { - var elements = _Global.document.querySelectorAll("." + _Constants.appBarClass); - if (elements) { - var len = elements.length; - for (var i = 0; i < len; i++) { - var element = elements[i]; - var appbar = element.winControl; - if (appbar && !element.disabled) { - appbar._manipulationChanged(event); - } - } - } - } - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/appBarAriaLabel").value; }, - get requiresCommands() { return "Invalid argument: commands must not be empty"; }, - get cannotChangePlacementWhenVisible() { return "Invalid argument: The placement property cannot be set when the AppBar is visible, call hide() first"; }, - get cannotChangeLayoutWhenVisible() { return "Invalid argument: The layout property cannot be set when the AppBar is visible, call hide() first"; } - }; - - var _LegacyAppBar = _Base.Class.derive(_Overlay._Overlay, function _LegacyAppBar_ctor(element, options) { - /// - /// - /// Creates a new _LegacyAppBar control. - /// - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the new _LegacyAppBar control. - /// - /// - /// The new _LegacyAppBar control. - /// - /// - - this._initializing = true; - - // Simplify checking later - options = options || {}; - - // Make sure there's an element - this._element = element || _Global.document.createElement("div"); - this._id = this._element.id || _ElementUtilities._uniqueID(this._element); - this._writeProfilerMark("constructor,StartTM"); - - // Attach our css class. - _ElementUtilities.addClass(this._element, _Constants.appBarClass); - - var that = this; - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._element, - tabIndex: this._element.hasAttribute("tabIndex") ? this._element.tabIndex : -1, - onLightDismiss: function () { - that.close(); - }, - onTakeFocus: function (useSetActive) { - if (!that._dismissable.restoreFocus()) { - that._layoutImpl.setFocusOnShow(); - } - }, - }); - - // Make sure we have an ARIA role - var role = this._element.getAttribute("role"); - if (!role) { - this._element.setAttribute("role", "menubar"); - } - var label = this._element.getAttribute("aria-label"); - if (!label) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - - // Call the _Overlay constructor helper to finish setting up our element. - // Don't pass constructor options, _LegacyAppBar needs to set those itself specific order. - this._baseOverlayConstructor(this._element); - - // Start off hidden - this._lastPositionVisited = displayModeVisiblePositions.none; - _ElementUtilities.addClass(this._element, _Constants.hiddenClass); - - // Add Invoke button. - this._invokeButton = _Global.document.createElement("button"); - this._invokeButton.tabIndex = 0; - this._invokeButton.setAttribute("type", "button"); - this._invokeButton.innerHTML = ""; - _ElementUtilities.addClass(this._invokeButton, _Constants.invokeButtonClass); - this._element.appendChild(this._invokeButton); - this._invokeButton.addEventListener("click", function () { - if (that.opened) { - that._hide(); - } else { - that._show(); - } - }, false); - - // Run layout setter immediately. We need to know our layout in order to correctly - // position any commands that may be getting set through the constructor. - this._layout = _Constants.appBarLayoutCustom; - delete options._layout; - - // Need to set placement before closedDisplayMode, closedDisplayMode sets our starting position, which is dependant on placement. - this.placement = options.placement || _Constants.appBarPlacementBottom; - this.closedDisplayMode = options.closedDisplayMode || closedDisplayModes.compact; - - _Control.setOptions(this, options); - - var commandsUpdatedBound = this._commandsUpdated.bind(this); - this._element.addEventListener(_Constants.commandVisibilityChanged, function (ev) { - if (that._disposed) { - return; - } - if (that.opened) { - ev.preventDefault(); - } - commandsUpdatedBound(); - }); - - this._initializing = false; - - this._setFocusToAppBarBound = this._setFocusToAppBar.bind(this); - - // Handle key down (left & right) - this._element.addEventListener("keydown", this._handleKeyDown.bind(this), false); - - // Attach global event handlers - if (!globalEventsInitialized) { - // Need to know if the IHM is done scrolling - _Global.document.addEventListener("MSManipulationStateChanged", _allManipulationChanged, false); - - globalEventsInitialized = true; - } - - if (this.closedDisplayMode === closedDisplayModes.none && this.layout === _Constants.appBarLayoutCommands) { - // Remove the commands layout _LegacyAppBar from the layout tree at this point so we don't cause unnecessary layout costs whenever - // the window resizes or when CSS changes are applied to the commands layout _LegacyAppBar's parent element. - this._element.style.display = "none"; - } - - this._winKeyboard = new _KeyboardBehavior._WinKeyboard(this._element); - - this._writeProfilerMark("constructor,StopTM"); - - return this; - }, { - // Public Properties - - /// The placement of the _LegacyAppBar on the display. Values are "top" or "bottom". - placement: { - get: function _LegacyAppBar_get_placement() { - return this._placement; - }, - set: function _LegacyAppBar_set_placement(value) { - // In designer we may have to move it - var wasShown = false; - if (_WinRT.Windows.ApplicationModel.DesignMode.designModeEnabled) { - this._hide(); - wasShown = true; - } - - if (this.opened) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.CannotChangePlacementWhenVisible", strings.cannotChangePlacementWhenVisible); - } - - // Set placement, coerce invalid values to 'bottom' - this._placement = (value === _Constants.appBarPlacementTop) ? _Constants.appBarPlacementTop : _Constants.appBarPlacementBottom; - - // Clean up win-top, win-bottom styles - if (this._placement === _Constants.appBarPlacementTop) { - _ElementUtilities.addClass(this._element, _Constants.topClass); - _ElementUtilities.removeClass(this._element, _Constants.bottomClass); - } else if (this._placement === _Constants.appBarPlacementBottom) { - _ElementUtilities.removeClass(this._element, _Constants.topClass); - _ElementUtilities.addClass(this._element, _Constants.bottomClass); - } - - // Update our position on screen. - this._ensurePosition(); - if (wasShown) { - // Show again if we hid ourselves for the designer - this._show(); - } - } - }, - - _layout: { - get: function _LegacyAppBar_get_layout() { - return this._layoutImpl.type; - }, - set: function (layout) { - if (layout !== _Constants.appBarLayoutCommands && - layout !== _Constants.appBarLayoutCustom && - layout !== _Constants.appBarLayoutMenu) { - } - - // In designer we may have to redraw it - var wasShown = false; - if (_WinRT.Windows.ApplicationModel.DesignMode.designModeEnabled) { - this._hide(); - wasShown = true; - } - - if (this.opened) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.CannotChangeLayoutWhenVisible", strings.cannotChangeLayoutWhenVisible); - } - - var commands; - if (!this._initializing) { - // Gather commands in preparation for hand off to new layout. - // We expect prev layout to return commands in the order they were set in, - // not necessarily the current DOM order the layout is using. - commands = this._layoutImpl.commandsInOrder; - this._layoutImpl.disconnect(); - } - - // Set layout - if (layout === _Constants.appBarLayoutCommands) { - this._layoutImpl = new _Layouts._AppBarCommandsLayout(); - } else if (layout === _Constants.appBarLayoutMenu) { - this._layoutImpl = new _Layouts._AppBarMenuLayout(); - } else { - // Custom layout uses Base _LegacyAppBar Layout class. - this._layoutImpl = new _Layouts._AppBarBaseLayout(); - } - this._layoutImpl.connect(this._element); - - if (commands && commands.length) { - // Reset _LegacyAppBar since layout changed. - this._layoutCommands(commands); - } - - // Show again if we hid ourselves for the designer - if (wasShown) { - this._show(); - } - }, - configurable: true - }, - - /// - /// Sets the AppBarCommands in the _LegacyAppBar. This property accepts an array of AppBarCommand objects. - /// - commands: { - set: function _LegacyAppBar_set_commands(commands) { - // Fail if trying to set when shown - if (this.opened) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.CannotChangeCommandsWhenVisible", _Resources._formatString(_Overlay._Overlay.commonstrings.cannotChangeCommandsWhenVisible, "_LegacyAppBar")); - } - - // Dispose old commands before tossing them out. - if (!this._initializing) { - // AppBarCommands defined in markup don't want to be disposed during initialization. - this._disposeChildren(); - } - this._layoutCommands(commands); - } - }, - - _layoutCommands: function _LegacyAppBar_layoutCommands(commands) { - // Function precondition: _LegacyAppBar must not be shown. - - // Empties _LegacyAppBar HTML and repopulates with passed in commands. - _ElementUtilities.empty(this._element); - this._element.appendChild(this._invokeButton); // Keep our Show/Hide button. - - // In case they had only one command to set... - if (!Array.isArray(commands)) { - commands = [commands]; - } - - this._layoutImpl.layout(commands); - }, - - /// - /// Gets/Sets how _LegacyAppBar will display itself while hidden. Values are "none", "minimal" and '"compact". - /// - closedDisplayMode: { - get: function _LegacyAppBar_get_closedDisplayMode() { - return this._closedDisplayMode; - }, - set: function _LegacyAppBar_set_closedDisplayMode(value) { - var oldValue = this._closedDisplayMode; - - if (oldValue !== value) { - - // Determine if the visible position is changing. This can be used to determine if we need to delay updating closedDisplayMode related CSS classes - // to avoid affecting the animation. - var changeVisiblePosition = _ElementUtilities.hasClass(this._element, _Constants.hiddenClass) || _ElementUtilities.hasClass(this._element, _Constants.hidingClass); - - if (value === closedDisplayModes.none) { - this._closedDisplayMode = closedDisplayModes.none; - if (!changeVisiblePosition || !oldValue) { - _ElementUtilities.removeClass(this._element, _Constants.minimalClass); - _ElementUtilities.removeClass(this._element, _Constants.compactClass); - } - } else if (value === closedDisplayModes.minimal) { - this._closedDisplayMode = closedDisplayModes.minimal; - if (!changeVisiblePosition || !oldValue || oldValue === closedDisplayModes.none) { - _ElementUtilities.addClass(this._element, _Constants.minimalClass); - _ElementUtilities.removeClass(this._element, _Constants.compactClass); - } - } else { - // Compact is default fallback. - this._closedDisplayMode = closedDisplayModes.compact; - _ElementUtilities.addClass(this._element, _Constants.compactClass); - _ElementUtilities.removeClass(this._element, _Constants.minimalClass); - } - - // The invoke button has changed the amount of available space in the _LegacyAppBar. Layout might need to scale. - this._layoutImpl.resize(); - - if (changeVisiblePosition) { - // If the value is being set while we are not showing, change to our new position. - this._changeVisiblePosition(displayModeVisiblePositions[this._closedDisplayMode]); - } - } - }, - }, - - /// - opened: { - get: function () { - // Returns true if _LegacyAppBar is not 'hidden'. - return !_ElementUtilities.hasClass(this._element, _Constants.hiddenClass) && - !_ElementUtilities.hasClass(this._element, _Constants.hidingClass) && - this._doNext !== displayModeVisiblePositions.minimal && - this._doNext !== displayModeVisiblePositions.compact && - this._doNext !== displayModeVisiblePositions.none; - }, - set: function (opened) { - var currentlyOpen = this.opened; - if (opened && !currentlyOpen) { - this._show(); - } else if (!opened && currentlyOpen) { - this._hide(); - } - } - }, - - /// - /// Occurs immediately before the control is opened. - /// - onbeforeopen: createEvent(EVENTS.beforeOpen), - - /// - /// Occurs immediately after the control is opened. - /// - onafteropen: createEvent(EVENTS.afterOpen), - - /// - /// Occurs immediately before the control is closed. - /// - onbeforeclose: createEvent(EVENTS.beforeClose), - - /// - /// Occurs immediately after the control is closed. - /// - onafterclose: createEvent(EVENTS.afterClose), - - getCommandById: function (id) { - /// - /// - /// Retrieves the command with the specified ID from this _LegacyAppBar. - /// If more than one command is found, this method returns them all. - /// - /// Id of the command to return. - /// - /// The command found, an array of commands if more than one have the same ID, or null if no command is found. - /// - /// - var commands = this._layoutImpl.commandsInOrder.filter(function (command) { - return command.id === id || command.element.id === id; - }); - - if (commands.length === 1) { - return commands[0]; - } else if (commands.length === 0) { - return null; - } - - return commands; - }, - - showCommands: function (commands) { - /// - /// - /// Show the specified commands of the _LegacyAppBar. - /// - /// - /// An array of the commands to show. The array elements may be AppBarCommand objects, or the string identifiers (IDs) of commands. - /// - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.RequiresCommands", strings.requiresCommands); - } - - this._layoutImpl.showCommands(commands); - }, - - hideCommands: function (commands) { - /// - /// - /// Hides the specified commands of the _LegacyAppBar. - /// - /// Required. Command or Commands to hide, either String, DOM elements, or WinJS objects. - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.RequiresCommands", strings.requiresCommands); - } - - this._layoutImpl.hideCommands(commands); - }, - - showOnlyCommands: function (commands) { - /// - /// - /// Show the specified commands, hiding all of the others in the _LegacyAppBar. - /// - /// - /// An array of the commands to show. The array elements may be AppBarCommand objects, or the string identifiers (IDs) of commands. - /// - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI._LegacyAppBar.RequiresCommands", strings.requiresCommands); - } - - this._layoutImpl.showOnlyCommands(commands); - }, - - open: function () { - /// - /// - /// Opens the _LegacyAppBar, if closed and not disabled, regardless of other state. - /// - /// - // Just wrap the private one, turning off keyboard invoked flag - this._writeProfilerMark("show,StartTM"); - this._show(); - }, - - _show: function _LegacyAppBar_show() { - - var toPosition = displayModeVisiblePositions.shown; - var showing = null; - - // If we're already shown, we are just going to animate our position, not fire events or manage focus. - if (!this.disabled && (_ElementUtilities.hasClass(this._element, _Constants.hiddenClass) || _ElementUtilities.hasClass(this._element, _Constants.hidingClass))) { - showing = appbarShownState; - } - - this._changeVisiblePosition(toPosition, showing); - - if (showing) { - // Clean up tabbing behavior by making sure first and final divs are correct after showing. - this._updateFirstAndFinalDiv(); - - _LightDismissService.shown(this._dismissable); - } - }, - - close: function () { - /// - /// - /// Closes the _LegacyAppBar. - /// - /// - // Just wrap the private one - this._writeProfilerMark("hide,StartTM"); - this._hide(); - }, - - _hide: function _LegacyAppBar_hide(toPosition) { - - var toPosition = toPosition || displayModeVisiblePositions[this.closedDisplayMode]; - var hiding = null; - - // If were already hidden, we are just going to animate our position, not fire events or manage focus again. - if (!_ElementUtilities.hasClass(this._element, _Constants.hiddenClass) && !_ElementUtilities.hasClass(this._element, _Constants.hidingClass)) { - hiding = appbarHiddenState; - } - - this._changeVisiblePosition(toPosition, hiding); - }, - - _dispose: function _LegacyAppBar_dispose() { - _Dispose.disposeSubTree(this.element); - _LightDismissService.hidden(this._dismissable); - this._layoutImpl.dispose(); - this.disabled = true; - this.close(); - }, - - _disposeChildren: function _LegacyAppBar_disposeChildren() { - // Be purposeful about what we dispose. - this._layoutImpl.disposeChildren(); - }, - - _handleKeyDown: function _LegacyAppBar_handleKeyDown(event) { - // On Left/Right arrow keys, moves focus to previous/next AppbarCommand element. - - // If the current active element isn't an intrinsic part of the _LegacyAppBar, - // Layout might want to handle additional keys. - if (!this._invokeButton.contains(_Global.document.activeElement)) { - this._layoutImpl.handleKeyDown(event); - } - }, - - _visiblePixels: { - get: function () { - // Returns object containing pixel height of each visible position - return { - hidden: knownVisibleHeights.hidden, - minimal: knownVisibleHeights.minimal, - compact: Math.max(this._heightWithoutLabels || 0, knownVisibleHeights.compact), - // Element can change size as content gets added or removed or if it - // experinces style changes. We have to look this up at run time. - shown: this._element.offsetHeight, - }; - } - }, - - _visiblePosition: { - // Returns string value of our nearest, stationary, visible position. - get: function () { - // If we're animating into a new posistion, return the position we're animating into. - if (this._animating && displayModeVisiblePositions[this._element.winAnimating]) { - return this._element.winAnimating; - } else { - return this._lastPositionVisited; - } - } - }, - - _visible: { - // Returns true if our visible position is not completely hidden, else false. - get: function () { - return (this._visiblePosition !== displayModeVisiblePositions.none); - } - }, - - _changeVisiblePosition: function (toPosition, newState) { - /// - /// - /// Changes the visible position of the _LegacyAppBar. - /// - /// - /// Name of the visible position we want to move to. - /// - /// - /// Name of the state we are entering. Values can be "showing", "hiding" or null. - /// If the value is null, then we are not changing states, only changing visible position. - /// - /// - - if ((this._visiblePosition === toPosition && !this._keyboardObscured) || - (this.disabled && toPosition !== displayModeVisiblePositions.disabled)) { - // If we want to go where we already are, or we're disabled, return false. - this._afterPositionChange(null); - } else if (this._animating || this._needToHandleShowingKeyboard || this._needToHandleHidingKeyboard) { - // Only do one thing at a time. If we are already animating, - // or the IHM is animating, schedule this for later. - this._doNext = toPosition; - this._afterPositionChange(null); - } else { - // Begin position changing sequence. - - // Set the animating flag to block any queued position changes until we're done. - this._element.winAnimating = toPosition; - var performAnimation = this._initializing ? false : true; - - // Assume we are animating from the last position visited. - var fromPosition = this._lastPositionVisited; - - // We'll need to measure our element to determine how far we need to animate. - // Make sure we have accurate dimensions. - this._element.style.display = ""; - - // Are we hiding completely, or about to become visible? - var hidingCompletely = (toPosition === displayModeVisiblePositions.hidden); - - if (this._keyboardObscured) { - // We're changing position while covered by the IHM. - if (hidingCompletely) { - // If we're covered by the IHM we already look hidden. - // We can skip our animation and just hide. - performAnimation = false; - } else { - // Some portion of the _LegacyAppBar should be visible to users after its position changes. - - // Un-obscure ourselves and become visible to the user again. - // Need to animate to our desired position as if we were coming up from behind the keyboard. - fromPosition = displayModeVisiblePositions.hidden; - } - this._keyboardObscured = false; - } - - // Fire "before" event if we are changing state. - if (newState === appbarShownState) { - this._beforeShow(); - } else if (newState === appbarHiddenState) { - this._beforeHide(); - } - - // Position our element into the correct "end of animation" position, - // also accounting for any viewport scrolling or soft keyboard positioning. - this._ensurePosition(); - - this._element.style.opacity = 1; - this._element.style.visibility = "visible"; - - this._animationPromise = (performAnimation) ? this._animatePositionChange(fromPosition, toPosition) : Promise.wrap(); - this._animationPromise.then( - function () { this._afterPositionChange(toPosition, newState); }.bind(this), - function () { this._afterPositionChange(toPosition, newState); }.bind(this) - ); - } - }, - - _afterPositionChange: function _LegacyAppBar_afterPositionChange(newPosition, newState) { - // Defines body of work to perform after changing positions. - if (this._disposed) { - return; - } - - if (newPosition) { - - // Update closedDisplayMode related CSS classes, which were delayed from the closedDisplayMode setter to avoid affecting the animation - if (newPosition === displayModeVisiblePositions.minimal) { - _ElementUtilities.addClass(this._element, _Constants.minimalClass); - _ElementUtilities.removeClass(this._element, _Constants.compactClass); - } - - if (newPosition === displayModeVisiblePositions.hidden && this.closedDisplayMode === closedDisplayModes.none) { - _ElementUtilities.removeClass(this._element, _Constants.minimalClass); - _ElementUtilities.removeClass(this._element, _Constants.compactClass); - } - - // Clear animation flag and record having visited this position. - this._element.winAnimating = ""; - this._lastPositionVisited = newPosition; - - if (this._doNext === this._lastPositionVisited) { - this._doNext = ""; - } - - if (newState === appbarHiddenState) { - _LightDismissService.hidden(this._dismissable); - } - - if (newPosition === displayModeVisiblePositions.hidden) { - // Make sure animation is finished. - this._element.style.visibility = "hidden"; - this._element.style.display = "none"; - } - - // Clean up animation transforms. - var transformProperty = _BaseUtils._browserStyleEquivalents["transform"].scriptName; - this._element.style[transformProperty] = ""; - - // Fire "after" event if we changed state. - if (newState === appbarShownState) { - this._afterShow(); - } else if (newState === appbarHiddenState) { - this._afterHide(); - } - - // If we had something queued, do that - Scheduler.schedule(this._checkDoNext, Scheduler.Priority.normal, this, "WinJS.UI._LegacyAppBar._checkDoNext"); - } - - this._afterPositionChangeCallBack(); - }, - - _afterPositionChangeCallBack: function () { - // Leave this blank for unit tests to overwrite. - }, - - _beforeShow: function _LegacyAppBar_beforeShow() { - // In case their event 'beforeopen' event listener is going to manipulate commands, - // first see if there are any queued command animations we can handle while we're still hidden. - if (this._queuedCommandAnimation) { - this._showAndHideFast(this._queuedToShow, this._queuedToHide); - this._queuedToShow = []; - this._queuedToHide = []; - } - - // Make sure everything fits before showing - this._layoutImpl.scale(); - - if (this.closedDisplayMode === closedDisplayModes.compact) { - this._heightWithoutLabels = this._element.offsetHeight; - } - - _ElementUtilities.removeClass(this._element, _Constants.hiddenClass); - _ElementUtilities.addClass(this._element, _Constants.showingClass); - - // Send our "beforeopen" event - this._sendEvent(EVENTS.beforeOpen); - }, - - _afterShow: function _LegacyAppBar_afterShow() { - _ElementUtilities.removeClass(this._element, _Constants.showingClass); - _ElementUtilities.addClass(this._element, _Constants.shownClass); - - // Send our "afteropen" event - this._sendEvent(EVENTS.afterOpen); - this._writeProfilerMark("show,StopTM"); - }, - - _beforeHide: function _LegacyAppBar_beforeHide() { - - _ElementUtilities.removeClass(this._element, _Constants.shownClass); - _ElementUtilities.addClass(this._element, _Constants.hidingClass); - - // Send our "beforeclose" event - this._sendEvent(EVENTS.beforeClose); - }, - - _afterHide: function _LegacyAppBar_afterHide() { - - // In case their 'afterclose' event handler is going to manipulate commands, - // first see if there are any queued command animations we can handle now we're hidden. - if (this._queuedCommandAnimation) { - this._showAndHideFast(this._queuedToShow, this._queuedToHide); - this._queuedToShow = []; - this._queuedToHide = []; - } - - _ElementUtilities.removeClass(this._element, _Constants.hidingClass); - _ElementUtilities.addClass(this._element, _Constants.hiddenClass); - - // Send our "afterclose" event - this._sendEvent(EVENTS.afterClose); - this._writeProfilerMark("hide,StopTM"); - }, - - _animatePositionChange: function _LegacyAppBar_animatePositionChange(fromPosition, toPosition) { - // Determines and executes the proper transition between visible positions - - var layoutElementsAnimationPromise = this._layoutImpl.positionChanging(fromPosition, toPosition), - appBarElementAnimationPromise; - - // Get values in terms of pixels to perform animation. - var beginningVisiblePixelHeight = this._visiblePixels[fromPosition], - endingVisiblePixelHeight = this._visiblePixels[toPosition], - distance = Math.abs(endingVisiblePixelHeight - beginningVisiblePixelHeight), - offsetTop = (this._placement === _Constants.appBarPlacementTop) ? -distance : distance; - - if ((this._placement === _Constants.appBarPlacementTop) && - ((fromPosition === displayModeVisiblePositions.shown && - toPosition === displayModeVisiblePositions.compact) || - (fromPosition === displayModeVisiblePositions.compact && - toPosition === displayModeVisiblePositions.shown))) { - // Command icons remain in the same location on a top appbar - // when going from compact > shown or shown > compact. - offsetTop = 0; - } - - // Animate - if (endingVisiblePixelHeight > beginningVisiblePixelHeight) { - var fromOffset = { top: offsetTop + "px", left: "0px" }; - appBarElementAnimationPromise = Animations.showEdgeUI(this._element, fromOffset, { mechanism: "transition" }); - } else { - var toOffset = { top: offsetTop + "px", left: "0px" }; - appBarElementAnimationPromise = Animations.hideEdgeUI(this._element, toOffset, { mechanism: "transition" }); - } - - return Promise.join([layoutElementsAnimationPromise, appBarElementAnimationPromise]); - }, - - _checkDoNext: function _LegacyAppBar_checkDoNext() { - // Do nothing if we're still animating - if (this._animating || this._needToHandleShowingKeyboard || this._needToHandleHidingKeyboard || this._disposed) { - return; - } - - if (this._doNext === displayModeVisiblePositions.disabled || - this._doNext === displayModeVisiblePositions.hidden || - this._doNext === displayModeVisiblePositions.minimal || - this._doNext === displayModeVisiblePositions.compact) { - // Do hide first because animating commands would be easier - this._hide(this._doNext); - this._doNext = ""; - } else if (this._queuedCommandAnimation) { - // Do queued commands before showing if possible - this._showAndHideQueue(); - } else if (this._doNext === displayModeVisiblePositions.shown) { - // Show last so that we don't unnecessarily animate commands - this._show(); - this._doNext = ""; - } - }, - - // Set focus to the passed in _LegacyAppBar - _setFocusToAppBar: function _LegacyAppBar_setFocusToAppBar(useSetActive, scroller) { - if (!this._focusOnFirstFocusableElement(useSetActive, scroller)) { - // No first element, set it to appbar itself - _Overlay._Overlay._trySetActive(this._element, scroller); - } - }, - - _commandsUpdated: function _LegacyAppBar_commandsUpdated() { - // If we are still initializing then we don't have a layout yet so it doesn't need updating. - if (!this._initializing) { - this._layoutImpl.commandsUpdated(); - this._layoutImpl.scale(); - } - }, - - _beginAnimateCommands: function _LegacyAppBar_beginAnimateCommands(showCommands, hideCommands, otherVisibleCommands) { - // The parameters are 3 mutually exclusive arrays of win-command elements contained in this Overlay. - // 1) showCommands[]: All of the HIDDEN win-command elements that ARE scheduled to show. - // 2) hideCommands[]: All of the VISIBLE win-command elements that ARE scheduled to hide. - // 3) otherVisibleCommands[]: All VISIBLE win-command elements that ARE NOT scheduled to hide. - this._layoutImpl.beginAnimateCommands(showCommands, hideCommands, otherVisibleCommands); - }, - - _endAnimateCommands: function _LegacyAppBar_endAnimateCommands() { - this._layoutImpl.endAnimateCommands(); - this._endAnimateCommandsCallBack(); - }, - - _endAnimateCommandsCallBack: function _LegacyAppBar_endAnimateCommandsCallBack() { - // Leave this blank for unit tests to overwrite. - }, - - // Get the top offset for top appbars. - _getTopOfVisualViewport: function _LegacyAppBar_getTopOfVisualViewPort() { - return _Overlay._Overlay._keyboardInfo._visibleDocTop; - }, - - // Get the bottom offset for bottom appbars. - _getAdjustedBottom: function _LegacyAppBar_getAdjustedBottom() { - // Need the distance the IHM moved as well. - return _Overlay._Overlay._keyboardInfo._visibleDocBottomOffset; - }, - - _showingKeyboard: function _LegacyAppBar_showingKeyboard(event) { - // Remember keyboard showing state. - this._keyboardObscured = false; - this._needToHandleHidingKeyboard = false; - - // If we're already moved, then ignore the whole thing - if (_Overlay._Overlay._keyboardInfo._visible && this._alreadyInPlace()) { - return; - } - - this._needToHandleShowingKeyboard = true; - // If focus is in the appbar, don't cause scrolling. - if (this.opened && this._element.contains(_Global.document.activeElement)) { - event.ensuredFocusedElementInView = true; - } - - // Check if appbar moves or if we're ok leaving it obscured instead. - if (this._visible && this._placement !== _Constants.appBarPlacementTop && _Overlay._Overlay._isFlyoutVisible()) { - // Remember that we're obscured - this._keyboardObscured = true; - } else { - // Don't be obscured, clear _scrollHappened flag to give us inference later on when to re-show ourselves. - this._scrollHappened = false; - } - - // Also set timeout regardless, so we can clean up our _keyboardShowing flag. - var that = this; - _Global.setTimeout(function (e) { that._checkKeyboardTimer(e); }, _Overlay._Overlay._keyboardInfo._animationShowLength + _Overlay._Overlay._scrollTimeout); - }, - - _hidingKeyboard: function _LegacyAppBar_hidingKeyboard() { - // We'll either just reveal the current space under the IHM or restore the window height. - - // We won't be obscured - this._keyboardObscured = false; - this._needToHandleShowingKeyboard = false; - this._needToHandleHidingKeyboard = true; - - // We'll either just reveal the current space or resize the window - if (!_Overlay._Overlay._keyboardInfo._isResized) { - // If we're not completely hidden, only fake hiding under keyboard, or already animating, - // then snap us to our final position. - if (this._visible || this._animating) { - // Not resized, update our final position immediately - this._checkScrollPosition(); - this._element.style.display = ""; - } - this._needToHandleHidingKeyboard = false; - } - // Else resize should clear keyboardHiding. - }, - - _resize: function _LegacyAppBar_resize(event) { - // If we're hidden by the keyboard, then hide bottom appbar so it doesn't pop up twice when it scrolls - if (this._needToHandleShowingKeyboard) { - // Top is allowed to scroll off the top, but we don't want bottom to peek up when - // scrolled into view since we'll show it ourselves and don't want a stutter effect. - if (this._visible) { - if (this._placement !== _Constants.appBarPlacementTop && !this._keyboardObscured) { - // If viewport doesn't match window, need to vanish momentarily so it doesn't scroll into view, - // however we don't want to toggle the visibility="hidden" hidden flag. - this._element.style.display = "none"; - } - } - // else if we're top we stay, and if there's a flyout, stay obscured by the keyboard. - } else if (this._needToHandleHidingKeyboard) { - this._needToHandleHidingKeyboard = false; - if (this._visible || this._animating) { - // Snap to final position - this._checkScrollPosition(); - this._element.style.display = ""; - } - } - - // Make sure everything still fits. - if (!this._initializing) { - this._layoutImpl.resize(event); - } - }, - - _checkKeyboardTimer: function _LegacyAppBar_checkKeyboardTimer() { - if (!this._scrollHappened) { - this._mayEdgeBackIn(); - } - }, - - _manipulationChanged: function _LegacyAppBar_manipulationChanged(event) { - // See if we're at the not manipulating state, and we had a scroll happen, - // which is implicitly after the keyboard animated. - if (event.currentState === 0 && this._scrollHappened) { - this._mayEdgeBackIn(); - } - }, - - _mayEdgeBackIn: function _LegacyAppBar_mayEdgeBackIn() { - // May need to react to IHM being resized event - if (this._needToHandleShowingKeyboard) { - // If not top appbar or viewport isn't still at top, then need to show again - this._needToHandleShowingKeyboard = false; - // If obscured (IHM + flyout showing), it's ok to stay obscured. - // If bottom we have to move, or if top scrolled off screen. - if (!this._keyboardObscured && - (this._placement !== _Constants.appBarPlacementTop || _Overlay._Overlay._keyboardInfo._visibleDocTop !== 0)) { - var toPosition = this._visiblePosition; - this._lastPositionVisited = displayModeVisiblePositions.hidden; - this._changeVisiblePosition(toPosition, false); - } else { - // Ensure any animations dropped during the showing keyboard are caught up. - this._checkDoNext(); - } - } - this._scrollHappened = false; - }, - - _ensurePosition: function _LegacyAppBar_ensurePosition() { - // Position the _LegacyAppBar element relative to the top or bottom edge of the visible - // document, based on the the visible position we think we need to be in. - var offSet = this._computePositionOffset(); - this._element.style.bottom = offSet.bottom; - this._element.style.top = offSet.top; - - }, - - _computePositionOffset: function _LegacyAppBar_computePositionOffset() { - // Calculates and returns top and bottom offsets for the _LegacyAppBar element, relative to the top or bottom edge of the visible - // document. - var positionOffSet = {}; - - if (this._placement === _Constants.appBarPlacementBottom) { - // If the IHM is open, the bottom of the visual viewport may or may not be obscured - // Use _getAdjustedBottom to account for the IHM if it is covering the bottom edge. - positionOffSet.bottom = this._getAdjustedBottom() + "px"; - positionOffSet.top = ""; - } else if (this._placement === _Constants.appBarPlacementTop) { - positionOffSet.bottom = ""; - positionOffSet.top = this._getTopOfVisualViewport() + "px"; - } - - return positionOffSet; - }, - - _checkScrollPosition: function _LegacyAppBar_checkScrollPosition() { - // If IHM has appeared, then remember we may come in - if (this._needToHandleShowingKeyboard) { - // Tag that it's OK to edge back in. - this._scrollHappened = true; - return; - } - - // We only need to update if we're not completely hidden. - if (this._visible || this._animating) { - this._ensurePosition(); - // Ensure any animations dropped during the showing keyboard are caught up. - this._checkDoNext(); - } - }, - - _alreadyInPlace: function _LegacyAppBar_alreadyInPlace() { - // See if we're already where we're supposed to be. - var offSet = this._computePositionOffset(); - return (offSet.top === this._element.style.top && offSet.bottom === this._element.style.bottom); - }, - - // If there is a shown non-sticky _LegacyAppBar then it sets the firstDiv tabIndex to - // the minimum tabIndex found in the _LegacyAppBars and finalDiv to the max found. - // Otherwise sets their tabIndex to -1 so they are not tab stops. - _updateFirstAndFinalDiv: function _LegacyAppBar_updateFirstAndFinalDiv() { - var appBarFirstDiv = this._element.querySelectorAll("." + _Constants.firstDivClass); - appBarFirstDiv = appBarFirstDiv.length >= 1 ? appBarFirstDiv[0] : null; - - var appBarFinalDiv = this._element.querySelectorAll("." + _Constants.finalDivClass); - appBarFinalDiv = appBarFinalDiv.length >= 1 ? appBarFinalDiv[0] : null; - - // Remove the firstDiv & finalDiv if they are not at the appropriate locations - if (appBarFirstDiv && (this._element.children[0] !== appBarFirstDiv)) { - appBarFirstDiv.parentNode.removeChild(appBarFirstDiv); - appBarFirstDiv = null; - } - if (appBarFinalDiv && (this._element.children[this._element.children.length - 1] !== appBarFinalDiv)) { - appBarFinalDiv.parentNode.removeChild(appBarFinalDiv); - appBarFinalDiv = null; - } - - // Create and add the firstDiv & finalDiv if they don't already exist - if (!appBarFirstDiv) { - // Add a firstDiv that will be the first child of the appBar. - // On focus set focus to the last element of the AppBar. - appBarFirstDiv = _Global.document.createElement("div"); - // display: inline is needed so that the div doesn't take up space and cause the page to scroll on focus - appBarFirstDiv.style.display = "inline"; - appBarFirstDiv.className = _Constants.firstDivClass; - appBarFirstDiv.tabIndex = -1; - appBarFirstDiv.setAttribute("aria-hidden", "true"); - _ElementUtilities._addEventListener(appBarFirstDiv, "focusin", this._focusOnLastFocusableElementOrThis.bind(this), false); - // add to beginning - if (this._element.children[0]) { - this._element.insertBefore(appBarFirstDiv, this._element.children[0]); - } else { - this._element.appendChild(appBarFirstDiv); - } - } - if (!appBarFinalDiv) { - // Add a finalDiv that will be the last child of the appBar. - // On focus set focus to the first element of the AppBar. - appBarFinalDiv = _Global.document.createElement("div"); - // display: inline is needed so that the div doesn't take up space and cause the page to scroll on focus - appBarFinalDiv.style.display = "inline"; - appBarFinalDiv.className = _Constants.finalDivClass; - appBarFinalDiv.tabIndex = -1; - appBarFinalDiv.setAttribute("aria-hidden", "true"); - _ElementUtilities._addEventListener(appBarFinalDiv, "focusin", this._focusOnFirstFocusableElementOrThis.bind(this), false); - this._element.appendChild(appBarFinalDiv); - } - - - // invokeButton should be the second to last element in the _LegacyAppBar's tab order. Second to the finalDiv. - if (this._element.children[this._element.children.length - 2] !== this._invokeButton) { - this._element.insertBefore(this._invokeButton, appBarFinalDiv); - } - var elms = this._element.getElementsByTagName("*"); - var highestTabIndex = _ElementUtilities._getHighestTabIndexInList(elms); - this._invokeButton.tabIndex = highestTabIndex; - - // Update the tabIndex of the firstDiv & finalDiv - if (appBarFirstDiv) { - appBarFirstDiv.tabIndex = _ElementUtilities._getLowestTabIndexInList(elms); - } - if (appBarFinalDiv) { - appBarFinalDiv.tabIndex = highestTabIndex; - } - }, - - _writeProfilerMark: function _LegacyAppBar_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI._LegacyAppBar:" + this._id + ":" + text); - } - }, { - // Statics - _Events: EVENTS, - }); - - return _LegacyAppBar; - }) - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// Menu -/// Menu,Menus,Flyout,Flyouts,Statics -define('WinJS/Controls/Menu',[ - 'exports', - '../Core/_Global', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Resources', - '../Core/_WriteProfilerMark', - '../Promise', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - '../Utilities/_KeyboardBehavior', - './_LegacyAppBar/_Constants', - './Flyout', - './Flyout/_Overlay', - './Menu/_Command' -], function menuInit(exports, _Global, _Base, _BaseUtils, _ErrorFromName, _Resources, _WriteProfilerMark, Promise, _ElementUtilities, _Hoverable, _KeyboardBehavior, _Constants, Flyout, _Overlay, _Command) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// Represents a menu flyout for displaying commands. - /// - /// - /// Menu - /// - /// - /// - /// - /// ]]> - /// Raised just before showing a menu. - /// Raised immediately after a menu is fully shown. - /// Raised just before hiding a menu. - /// Raised immediately after a menu is fully hidden. - /// The Menu control itself - /// - /// - Menu: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/menuAriaLabel").value; }, - get requiresCommands() { return "Invalid argument: commands must not be empty"; }, - get nullCommand() { return "Invalid argument: command must not be null"; }, - }; - - function isCommandInMenu(object) { - // Verifies that we have a menuCommand element and that it is in a Menu. - var element = object.element || object; - return _ElementUtilities._matchesSelector(element, "." + _Constants.menuClass + " " + "." + _Constants.menuCommandClass); - } - - var Menu = _Base.Class.derive(Flyout.Flyout, function Menu_ctor(element, options) { - /// - /// - /// Creates a new Menu control. - /// - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the control. - /// - /// The new Menu control. - /// - /// - - // We need to be built on top of a Flyout, so stomp on the user's input - options = options || {}; - - // Make sure there's an input element - this._element = element || _Global.document.createElement("div"); - this._id = this._element.id || _ElementUtilities._uniqueID(this._element); - this._writeProfilerMark("constructor,StartTM"); - - // validate that if they didn't set commands, in which - // case any HTML only contains commands. Do this first - // so that we don't leave partial Menus in the DOM. - if (!options.commands && this._element) { - // Shallow copy object so we can modify it. - options = _BaseUtils._shallowCopy(options); - options.commands = this._verifyCommandsOnly(this._element, "WinJS.UI.MenuCommand"); - } - - // Remember aria role in case base constructor changes it - var role = this._element ? this._element.getAttribute("role") : null; - var label = this._element ? this._element.getAttribute("aria-label") : null; - - // Call the base overlay constructor helper - this._baseFlyoutConstructor(this._element, options); - - // Make sure we have an ARIA role - if (role === null || role === "" || role === undefined) { - this._element.setAttribute("role", "menu"); - } - if (label === null || label === "" || label === undefined) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - - // Handle "esc" & "up/down" key presses - this._element.addEventListener("keydown", this._handleKeyDown.bind(this), true); - this._element.addEventListener(_Constants._menuCommandInvokedEvent, this._handleCommandInvoked.bind(this), false); - this._element.addEventListener("mouseover", this._handleMouseOver.bind(this), false); - this._element.addEventListener("mouseout", this._handleMouseOut.bind(this), false); - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.menuClass); - - this._winKeyboard = new _KeyboardBehavior._WinKeyboard(this._element); - - // Need to set our commands, making sure we're hidden first - this.hide(); - this._writeProfilerMark("constructor,StopTM"); - }, { - // Public Properties - - /// - /// Sets the MenuCommand objects that appear in the Menu. You can set this to a single MenuCommand or an array of MenuCommand objects. - /// - /// - commands: { - set: function (value) { - // Fail if trying to set when visible - if (!this.hidden) { - throw new _ErrorFromName("WinJS.UI.Menu.CannotChangeCommandsWhenVisible", _Resources._formatString(_Overlay._Overlay.commonstrings.cannotChangeCommandsWhenVisible, "Menu")); - } - - // Start from scratch - _ElementUtilities.empty(this._element); - - // In case they had only one... - if (!Array.isArray(value)) { - value = [value]; - } - - // Add commands - var len = value.length; - for (var i = 0; i < len; i++) { - this._addCommand(value[i]); - } - } - }, - - getCommandById: function (id) { - /// - /// - /// Retrieve the command with the specified ID from this Menu. If more than one command is found, all are returned. - /// - /// The ID of the command to find. - /// - /// The command found, an array of commands if more than one have the same ID, or null if no command is found. - /// - /// - /// - var commands = this.element.querySelectorAll("#" + id); - var newCommands = []; - for (var count = 0, len = commands.length; count < len; count++) { - if (commands[count].winControl) { - newCommands.push(commands[count].winControl); - } - } - - if (newCommands.length === 1) { - return newCommands[0]; - } else if (newCommands.length === 0) { - return null; - } - - return newCommands; - }, - - - showCommands: function (commands) { - /// - /// - /// Shows the specified commands of the Menu. - /// - /// - /// The commands to show. The array elements may be Menu objects, or the string identifiers (IDs) of commands. - /// - /// - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI.Menu.RequiresCommands", strings.requiresCommands); - } - - this._showCommands(commands, true); - }, - - hideCommands: function (commands) { - /// - /// - /// Hides the Menu. - /// - /// - /// Required. Command or Commands to hide, either String, DOM elements, or WinJS objects. - /// - /// - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI.Menu.RequiresCommands", strings.requiresCommands); - } - - this._hideCommands(commands, true); - }, - - showOnlyCommands: function (commands) { - /// - /// - /// Shows the specified commands of the Menu while hiding all other commands. - /// - /// - /// The commands to show. The array elements may be MenuCommand objects, or the string identifiers (IDs) of commands. - /// - /// - /// - if (!commands) { - throw new _ErrorFromName("WinJS.UI.Menu.RequiresCommands", strings.requiresCommands); - } - - this._showOnlyCommands(commands, true); - }, - - show: function (anchor, placement, alignment) { - /// - /// - /// Shows the Menu, if hidden, regardless of other states. - /// - /// - /// The DOM element, or ID of a DOM element, to anchor the Menu. This parameter overrides the anchor property for this method call only. - /// - /// - /// The placement of the Menu to the anchor: 'auto' (default), 'autohorizontal', 'autovertical', 'top', 'bottom', 'left', or 'right'. This parameter overrides the placement - /// property for this method call only. - /// - /// - /// For 'top' or 'bottom' placement, the alignment of the Menu to the anchor's edge: 'center' (default), 'left', or 'right'. This parameter - /// overrides the alignment property for this method call only. - /// - /// - /// - // Just call private version to make appbar flags happy - this._writeProfilerMark("show,StartTM"); // The corresponding "stop" profiler mark is handled in _Overlay._baseEndShow(). - this._show(anchor, placement, alignment); - }, - - _show: function Menu_show(anchor, placement, alignment) { - if (!_ElementUtilities.hasClass(this.element, _Constants.menuMouseSpacingClass) && !_ElementUtilities.hasClass(this.element, _Constants.menuTouchSpacingClass)) { - // The Menu's spacing shouldn't change while it is already shown. Only - // add a spacing class if it doesn't already have one. It will get - // removed after the Menu hides. - _ElementUtilities.addClass( - this.element, - Flyout.Flyout._cascadeManager.inputType === _KeyboardBehavior._InputTypes.mouse || Flyout.Flyout._cascadeManager.inputType === _KeyboardBehavior._InputTypes.keyboard ? - _Constants.menuMouseSpacingClass : - _Constants.menuTouchSpacingClass - ); - } - // Call flyout show - this._baseFlyoutShow(anchor, placement, alignment); - - // Menu will need to adjust MenuCommand layouts based on the various - // types of commands visible in our Menu, but only after we send the beforeshow - // event, so the developer has a chance to show or hide more commands. - // Flyout's _findPosition will make that call. - }, - - _hide: function Menu_hide() { - if (this._hoverPromise) { - this._hoverPromise.cancel(); - } - Flyout.Flyout.prototype._hide.call(this); - }, - - _beforeEndHide: function Menu_beforeEndHide() { - _ElementUtilities.removeClass(this.element, _Constants.menuMouseSpacingClass); - _ElementUtilities.removeClass(this.element, _Constants.menuTouchSpacingClass); - Flyout.Flyout.prototype._beforeEndHide.call(this); - }, - - _addCommand: function Menu_addCommand(command) { - if (!command) { - throw new _ErrorFromName("WinJS.UI.Menu.NullCommand", strings.nullCommand); - } - // See if it's a command already - if (!command._element) { - // Not a command, so assume it's options for a command - command = new _Command.MenuCommand(null, command); - } - // If we were attached somewhere else, detach us - if (command._element.parentElement) { - command._element.parentElement.removeChild(command._element); - } - - // Reattach us - this._element.appendChild(command._element); - }, - - _dispose: function Menu_dispose() { - if (this._hoverPromise) { - this._hoverPromise.cancel(); - } - Flyout.Flyout.prototype._dispose.call(this); - - }, - - _commandsUpdated: function Menu_commandsUpdated() { - if (!this.hidden) { - this._checkMenuCommands(); - } - }, - - // Called when we show/hide commands or by flyout's _findPosition when the Menu is showing. - _checkMenuCommands: function Menu_checkMenuCommands() { - var menuCommands = this._element.querySelectorAll(".win-command"), - hasToggleCommands = false, - hasFlyoutCommands = false; - if (menuCommands) { - for (var i = 0, len = menuCommands.length; i < len; i++) { - var menuCommand = menuCommands[i].winControl; - if (menuCommand && !menuCommand.hidden) { - if (!hasToggleCommands && menuCommand.type === _Constants.typeToggle) { - hasToggleCommands = true; - } - if (!hasFlyoutCommands && menuCommand.type === _Constants.typeFlyout) { - hasFlyoutCommands = true; - } - } - } - } - - _ElementUtilities[hasToggleCommands ? 'addClass' : 'removeClass'](this._element, _Constants.menuContainsToggleCommandClass); - _ElementUtilities[hasFlyoutCommands ? 'addClass' : 'removeClass'](this._element, _Constants.menuContainsFlyoutCommandClass); - }, - - _handleKeyDown: function Menu_handleKeyDown(event) { - if (event.keyCode === Key.upArrow) { - Menu._focusOnPreviousElement(this.element); - - // Prevent the page from scrolling - event.preventDefault(); - } else if (event.keyCode === Key.downArrow) { - Menu._focusOnNextElement(this.element); - - // Prevent the page from scrolling - event.preventDefault(); - } else if ((event.keyCode === Key.space || event.keyCode === Key.enter) - && (this.element === _Global.document.activeElement)) { - event.preventDefault(); - this.hide(); - } else if (event.keyCode === Key.tab) { - event.preventDefault(); - } - }, - - _handleFocusIn: function Menu_handleFocusIn(event) { - // Menu focuses commands on mouseover. We need to handle cases involving activated flyout commands - // to ensure that mousing over different commands in a menu closes that command's sub flyout. - var target = event.target; - if (isCommandInMenu(target)) { - var command = target.winControl; - if (_ElementUtilities.hasClass(command.element, _Constants.menuCommandFlyoutActivatedClass)) { - // If it's an activated 'flyout' typed command, move focus onto the command's subFlyout. - // We expect this will collapse all decendant Flyouts of the subFlyout from the cascade. - command.flyout.element.focus(); - } else { - // Deactivate any currently activated command in the Menu to subsequently trigger all subFlyouts descendants to collapse. - var activatedSiblingCommand = this.element.querySelector("." + _Constants.menuCommandFlyoutActivatedClass); - if (activatedSiblingCommand) { - _Command.MenuCommand._deactivateFlyoutCommand(activatedSiblingCommand); - } - } - } else if (target === this.element) { - // The Menu itself is receiving focus. Rely on the Flyout base implementation to notify the cascadeManager. - // We expect this will only happen when other Menu event handling code causes the Menu to focus itself. - Flyout.Flyout.prototype._handleFocusIn.call(this, event); - } - }, - - _handleCommandInvoked: function Menu_handleCommandInvoked(event) { - // Cascading Menus hide when invoking a command commits an action, not when invoking a command opens a subFlyout. - if (this._hoverPromise) { - // Prevent pending duplicate invoke triggered via hover. - this._hoverPromise.cancel(); - } - var command = event.detail.command; - if (command._type !== _Constants.typeFlyout && command._type !== _Constants.typeSeparator) { - this._lightDismiss(); // Collapse all Menus/Flyouts. - } - }, - - _hoverPromise: null, - _handleMouseOver: function Menu_handleMouseOver(event) { - var target = event.target; - if (isCommandInMenu(target)) { - var command = target.winControl, - that = this; - - if (target.focus) { - target.focus(); - // remove keyboard focus rect since focus has been triggered by mouse over. - _ElementUtilities.removeClass(target, "win-keyboard"); - - if (command.type === _Constants.typeFlyout && command.flyout && command.flyout.hidden) { - this._hoverPromise = this._hoverPromise || Promise.timeout(_Constants.menuCommandHoverDelay).then( - function () { - if (!that.hidden && !that._disposed) { - command._invoke(event); - } - that._hoverPromise = null; - }, - function () { - that._hoverPromise = null; - }); - } - } - } - }, - - _handleMouseOut: function Menu_handleMouseOut(event) { - var target = event.target; - if (isCommandInMenu(target) && !target.contains(event.relatedTarget)) { - if (target === _Global.document.activeElement) { - // Menu gives focus to the menu itself - this.element.focus(); - } - if (this._hoverPromise) { - this._hoverPromise.cancel(); - } - } - }, - - _writeProfilerMark: function Menu_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI.Menu:" + this._id + ":" + text); - } - }); - - // Statics - - // Set focus to next focusable element in the menu (loop if necessary). - // Note: The loop works by first setting focus to the menu itself. If the menu is - // what had focus before, then we break. Otherwise we try the first child next. - // Focus remains on the menu if nothing is focusable. - Menu._focusOnNextElement = function (menu) { - var _currentElement = _Global.document.activeElement; - - do { - if (_currentElement === menu) { - _currentElement = _currentElement.firstElementChild; - } else { - _currentElement = _currentElement.nextElementSibling; - } - - if (_currentElement) { - _currentElement.focus(); - } else { - _currentElement = menu; - } - - } while (_currentElement !== _Global.document.activeElement); - }; - - // Set focus to previous focusable element in the menu (loop if necessary). - // Note: The loop works by first setting focus to the menu itself. If the menu is - // what had focus before, then we break. Otherwise we try the last child next. - // Focus remains on the menu if nothing is focusable. - Menu._focusOnPreviousElement = function (menu) { - var _currentElement = _Global.document.activeElement; - - do { - if (_currentElement === menu) { - _currentElement = _currentElement.lastElementChild; - } else { - _currentElement = _currentElement.previousElementSibling; - } - - if (_currentElement) { - _currentElement.focus(); - } else { - _currentElement = menu; - } - - } while (_currentElement !== _Global.document.activeElement); - }; - - return Menu; - }) - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/AutoSuggestBox/_SearchSuggestionManagerShim',[ - 'exports', - '../../_Signal', - '../../Core/_Base', - '../../Core/_BaseUtils', - '../../Core/_Events', - '../../BindingList', -], function SearchSuggestionManagerShimInit(exports, _Signal, _Base, _BaseUtils, _Events, BindingList) { - "use strict"; - - var CollectionChange = { - reset: 0, - itemInserted: 1, - itemRemoved: 2, - itemChanged: 3 - }; - var SearchSuggestionKind = { - Query: 0, - Result: 1, - Separator: 2 - }; - - var SuggestionVectorShim = _Base.Class.derive(Array, function SuggestionVectorShim_ctor() { - }, { - reset: function () { - this.length = 0; - this.dispatchEvent("vectorchanged", { collectionChange: CollectionChange.reset, index: 0 }); - }, - - insert: function (index, data) { - this.splice(index, 0, data); - this.dispatchEvent("vectorchanged", { collectionChange: CollectionChange.itemInserted, index: index }); - }, - - remove: function (index) { - this.splice(index, 1); - this.dispatchEvent("vectorchanged", { collectionChange: CollectionChange.itemRemoved, index: index }); - }, - }); - _Base.Class.mix(SuggestionVectorShim, _Events.eventMixin); - - var SearchSuggestionCollectionShim = _Base.Class.define(function SearchSuggestionCollectionShim_ctor() { - this._data = []; - }, { - size: { - get: function () { - return this._data.length; - } - }, - - appendQuerySuggestion: function (text) { - this._data.push({ kind: SearchSuggestionKind.Query, text: text }); - }, - appendQuerySuggestions: function (suggestions) { - suggestions.forEach(this.appendQuerySuggestion.bind(this)); - }, - appendResultSuggestion: function (text, detailText, tag, imageUrl, imageAlternateText) { - // 'image' must be null (not undefined) for SearchBox to fallback to use imageUrl instead - this._data.push({ kind: SearchSuggestionKind.Result, text: text, detailText: detailText, tag: tag, imageUrl: imageUrl, imageAlternateText: imageAlternateText, image: null }); - }, - appendSearchSeparator: function (label) { - this._data.push({ kind: SearchSuggestionKind.Separator, text: label }); - } - }); - - var SuggestionsRequestedEventArgShim = _Base.Class.define(function SuggestionsRequestedEventArgShim_ctor(queryText, language, linguisticDetails) { - this._queryText = queryText; - this._language = language; - this._linguisticDetails = linguisticDetails; - this._searchSuggestionCollection = new SearchSuggestionCollectionShim(); - }, { - language: { - get: function () { - return this._language; - } - }, - linguisticDetails: { - get: function () { - return this._linguisticDetails; - } - }, - queryText: { - get: function () { - return this._queryText; - } - }, - searchSuggestionCollection: { - get: function () { - return this._searchSuggestionCollection; - } - }, - getDeferral: function () { - return this._deferralSignal || (this._deferralSignal = new _Signal()); - }, - - _deferralSignal: null, - }); - - var SearchSuggestionManagerShim = _Base.Class.define(function SearchSuggestionManagerShim_ctor() { - this._updateVector = this._updateVector.bind(this); - - this._suggestionVector = new SuggestionVectorShim(); - this._query = ""; - this._history = { "": [] }; - - this._dataSource = []; - - this.searchHistoryContext = ""; - this.searchHistoryEnabled = true; - }, { - addToHistory: function (queryText /*, language */) { - if (!queryText || !queryText.trim()) { - return; - } - - var history = this._history[this.searchHistoryContext]; - var dupeIndex = -1; - for (var i = 0, l = history.length; i < l; i++) { - var item = history[i]; - if (item.text.toLowerCase() === queryText.toLowerCase()) { - dupeIndex = i; - break; - } - } - if (dupeIndex >= 0) { - history.splice(dupeIndex, 1); - } - - history.splice(0, 0, { text: queryText, kind: SearchSuggestionKind.Query }); - this._updateVector(); - }, - - clearHistory: function () { - this._history[this.searchHistoryContext] = []; - this._updateVector(); - }, - - setLocalContentSuggestionSettings: function (settings) { - }, - - setQuery: function (queryText) { - var that = this; - function update(arr) { - that._dataSource = arr; - that._updateVector(); - } - - this._query = queryText; - var arg = new SuggestionsRequestedEventArgShim(queryText); - this.dispatchEvent("suggestionsrequested", { request: arg }); - if (arg._deferralSignal) { - arg._deferralSignal.promise.then(update.bind(this, arg.searchSuggestionCollection._data)); - } else { - update(arg.searchSuggestionCollection._data); - } - }, - - searchHistoryContext: { - get: function () { - return "" + this._searchHistoryContext; - }, - set: function (value) { - value = "" + value; - if (!this._history[value]) { - this._history[value] = []; - } - this._searchHistoryContext = value; - } - }, - - searchHistoryEnabled: { - get: function () { - return this._searchHistoryEnabled; - }, - set: function (value) { - this._searchHistoryEnabled = value; - } - }, - - suggestions: { - get: function () { - return this._suggestionVector; - } - }, - - _updateVector: function () { - // Can never clear the entire suggestions list or it will cause a visual flash because - // the SearchBox control removes the suggestions list UI when the SSM fires vectorChanged - // with size === 0, then re-renders it when the first suggestion is added. - // Workaround is to insert a dummy entry, remove all old entries, add the new set of - // eligible suggestions, then remove the dummy entry. - this.suggestions.insert(this.suggestions.length, { text: "", kind: SearchSuggestionKind.Query }); - - while (this.suggestions.length > 1) { - this.suggestions.remove(0); - } - - var index = 0; - var added = {}; - if (this.searchHistoryEnabled) { - var q = this._query.toLowerCase(); - this._history[this.searchHistoryContext].forEach(function (item) { - var text = item.text.toLowerCase(); - if (text.indexOf(q) === 0) { - this.suggestions.insert(index, item); - added[text] = true; - index++; - } - }, this); - } - this._dataSource.forEach(function (item) { - if (item.kind === SearchSuggestionKind.Query) { - if (!added[item.text.toLowerCase()]) { - this.suggestions.insert(index, item); - index++; - } - } else { - this.suggestions.insert(index, item); - index++; - } - }, this); - - this.suggestions.remove(this.suggestions.length - 1); - }, - }); - _Base.Class.mix(SearchSuggestionManagerShim, _Events.eventMixin); - - _Base.Namespace._moduleDefine(exports, null, { - _CollectionChange: CollectionChange, - _SearchSuggestionKind: SearchSuggestionKind, - _SearchSuggestionManagerShim: SearchSuggestionManagerShim, - }); -}); - -define('require-style!less/styles-autosuggestbox',[],function(){}); - -define('require-style!less/colors-autosuggestbox',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/AutoSuggestBox',[ - "exports", - "../Core/_Global", - "../Core/_WinRT", - "../Core/_Base", - "../Core/_ErrorFromName", - "../Core/_Events", - "../Core/_Resources", - "../Utilities/_Control", - "../Utilities/_ElementListUtilities", - "../Utilities/_ElementUtilities", - '../Utilities/_Hoverable', - "../_Accents", - "../Animations", - "../BindingList", - "../Promise", - "./Repeater", - "./AutoSuggestBox/_SearchSuggestionManagerShim", - "require-style!less/styles-autosuggestbox", - "require-style!less/colors-autosuggestbox" -], function autoSuggestBoxInit(exports, _Global, _WinRT, _Base, _ErrorFromName, _Events, _Resources, _Control, _ElementListUtilities, _ElementUtilities, _Hoverable, _Accents, Animations, BindingList, Promise, Repeater, _SuggestionManagerShim) { - "use strict"; - - _Accents.createAccentRule("html.win-hoverable .win-autosuggestbox .win-autosuggestbox-suggestion-selected:hover", [{ name: "background-color", value: _Accents.ColorTypes.listSelectHover }]); - _Accents.createAccentRule(".win-autosuggestbox .win-autosuggestbox-suggestion-selected", [{ name: "background-color", value: _Accents.ColorTypes.listSelectRest }]); - _Accents.createAccentRule(".win-autosuggestbox .win-autosuggestbox-suggestion-selected.win-autosuggestbox-suggestion-selected:hover:active", [{ name: "background-color", value: _Accents.ColorTypes.listSelectPress }]); - - var ClassNames = { - asb: "win-autosuggestbox", - asbDisabled: "win-autosuggestbox-disabled", - asbFlyout: "win-autosuggestbox-flyout", - asbFlyoutAbove: "win-autosuggestbox-flyout-above", - asbBoxFlyoutHighlightText: "win-autosuggestbox-flyout-highlighttext", - asbHitHighlightSpan: "win-autosuggestbox-hithighlight-span", - asbInput: "win-autosuggestbox-input", - asbInputFocus: "win-autosuggestbox-input-focus", - asbSuggestionQuery: "win-autosuggestbox-suggestion-query", - asbSuggestionResult: "win-autosuggestbox-suggestion-result", - asbSuggestionResultText: "win-autosuggestbox-suggestion-result-text", - asbSuggestionResultDetailedText: "win-autosuggestbox-suggestion-result-detailed-text", - asbSuggestionSelected: "win-autosuggestbox-suggestion-selected", - asbSuggestionSeparator: "win-autosuggestbox-suggestion-separator", - }; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// A rich input box that provides suggestions as the user types. - /// - /// - /// - /// - /// - /// ]]> - /// Raised when user or app changes the query text. - /// Raised when user presses Enter. - /// Raised when user clicks one of the displayed suggestions. - /// Raised when the system requests suggestions from this app. - /// Styles the entire Auto Suggest Box control. - /// Styles the query input box. - /// Styles the result suggestions flyout. - /// Styles the query type suggestion. - /// Styles the result type suggestion. - /// Styles the currently selected suggestion. - /// Styles the separator type suggestion. - /// - /// - AutoSuggestBox: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - var EventNames = { - querychanged: "querychanged", - querysubmitted: "querysubmitted", - resultsuggestionchosen: "resultsuggestionchosen", - suggestionsrequested: "suggestionsrequested" - }; - - var Strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get invalidSuggestionKind() { return "Error: Invalid suggestion kind."; }, - - get ariaLabel() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabel").value; }, - get ariaLabelInputNoPlaceHolder() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabelInputNoPlaceHolder").value; }, - get ariaLabelInputPlaceHolder() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabelInputPlaceHolder").value; }, - get ariaLabelQuery() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabelQuery").value; }, - get ariaLabelResult() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabelResult").value; }, - get ariaLabelSeparator() { return _Resources._getWinJSString("ui/autoSuggestBoxAriaLabelSeparator").value; }, - }; - - var AutoSuggestBox = _Base.Class.define(function asb_ctor(element, options) { - /// - /// - /// Creates a new AutoSuggestBox. - /// - /// - /// The DOM element that hosts the AutoSuggestBox. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the querychanged event, - /// add a property named "onquerychanged" to the options object and set its value to the event handler. - /// This parameter is optional. - /// - /// - /// The new AutoSuggestBox. - /// - /// - /// - element = element || _Global.document.createElement("div"); - options = options || {}; - - if (element.winControl) { - throw new _ErrorFromName("WinJS.UI.AutoSuggestBox.DuplicateConstruction", Strings.duplicateConstruction); - } - - this._suggestionsChangedHandler = this._suggestionsChangedHandler.bind(this); - this._suggestionsRequestedHandler = this._suggestionsRequestedHandler.bind(this); - - this._element = element; - element.winControl = this; - element.classList.add(ClassNames.asb); - element.classList.add("win-disposable"); - - this._setupDOM(); - this._setupSSM(); - - this._chooseSuggestionOnEnter = false; - this._currentFocusedIndex = -1; - this._currentSelectedIndex = -1; - this._flyoutOpenPromise = Promise.wrap(); - this._lastKeyPressLanguage = ""; - this._prevLinguisticDetails = this._getLinguisticDetails(); - this._prevQueryText = ""; - - _Control.setOptions(this, options); - - this._hideFlyout(); - }, { - /// - /// Raised when user clicks on one of the suggestions displayed. - /// - /// - onresultsuggestionchosen: _Events._createEventProperty(EventNames.resultsuggestionchosen), - - /// - /// Raised when user or app changes the query text. - /// - /// - onquerychanged: _Events._createEventProperty(EventNames.querychanged), - - /// - /// Raised when user submits the current query. - /// - /// - onquerysubmitted: _Events._createEventProperty(EventNames.querysubmitted), - - /// - /// Raised when Windows requests search suggestions from the app. - /// - /// - onsuggestionsrequested: _Events._createEventProperty(EventNames.suggestionsrequested), - - /// - element: { - get: function () { - return this._element; - } - }, - - /// - /// Gets or sets whether the first suggestion is chosen when the user presses Enter. When set to true, as the user types in the input box, a - /// focus rectangle is drawn on the first suggestion (if present and no IME composition in progress). Pressing enter will behave the same as - /// if clicked on the focused suggestion, and the down arrow key press will put real focus to the second suggestion and the up arrow key will - /// remove focus. - /// - /// - chooseSuggestionOnEnter: { - get: function () { - return this._chooseSuggestionOnEnter; - }, - set: function (value) { - this._chooseSuggestionOnEnter = !!value; - } - }, - - /// - /// Gets or sets a value that specifies whether the AutoSuggestBox is disabled. - /// - /// - disabled: { - get: function () { - return this._inputElement.disabled; - }, - set: function (value) { - if (this._inputElement.disabled === !!value) { - return; - } - - if (!value) { - this._enableControl(); - } else { - this._disableControl(); - } - } - }, - - /// - /// Gets or sets the placeholder text for the AutoSuggestBox. This text is displayed if there is no other text in the input box. - /// - /// - placeholderText: { - get: function () { - return this._inputElement.placeholder; - }, - set: function (value) { - this._inputElement.placeholder = value; - this._updateInputElementAriaLabel(); - } - }, - - /// - /// Gets or sets the query text for the AutoSuggestBox. - /// - /// - queryText: { - get: function () { - return this._inputElement.value; - }, - set: function (value) { - this._inputElement.value = ""; // This finalizes the IME composition - this._inputElement.value = value; - } - }, - - /// - /// Gets or sets a value that specifies whether history is disabled for the AutoSuggestBox. The default value is false. - /// - /// - searchHistoryDisabled: { - get: function () { - return !this._suggestionManager.searchHistoryEnabled; - }, - set: function (value) { - this._suggestionManager.searchHistoryEnabled = !value; - } - }, - - /// - /// Gets or sets the search history context for the AutoSuggestBox. The search history context string is used as a secondary key for storing search history. - /// (The primary key is the AppId.) An app can use the search history context string to store different search histories based on the context of the application. - /// If you don't set this property, the system assumes that all searches in your app occur in the same context. - /// If you update this property while the search pane is open with suggestions showing, the changes won't take effect until the user enters the next character. - /// - /// - searchHistoryContext: { - get: function () { - return this._suggestionManager.searchHistoryContext; - }, - set: function (value) { - this._suggestionManager.searchHistoryContext = value; - } - }, - - dispose: function asb_dispose() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - - // Cancel pending promises. - this._flyoutOpenPromise.cancel(); - - this._suggestions.removeEventListener("vectorchanged", this._suggestionsChangedHandler); - this._suggestionManager.removeEventListener("suggestionsrequested", this._suggestionsRequestedHandler); - - this._suggestionManager = null; - this._suggestions = null; - this._hitFinder = null; - - this._disposed = true; - }, - - setLocalContentSuggestionSettings: function asb_setLocalContentSuggestionSettings(settings) { - /// - /// - /// Specifies whether suggestions based on local files are automatically displayed in the input field, and defines the criteria that - /// the system uses to locate and filter these suggestions. - /// - /// - /// The new settings for local content suggestions. - /// - /// - /// - this._suggestionManager.setLocalContentSuggestionSettings(settings); - }, - - // Constructor Helpers - _setupDOM: function asb_setupDOM() { - var flyoutPointerReleasedHandler = this._flyoutPointerReleasedHandler.bind(this); - var inputOrImeChangeHandler = this._inputOrImeChangeHandler.bind(this); - - // Root element - if (!this._element.getAttribute("aria-label")) { - this._element.setAttribute("aria-label", Strings.ariaLabel); - } - this._element.setAttribute("role", "group"); - - // Input element - this._inputElement = _Global.document.createElement("input"); - this._inputElement.autocorrect = "off"; - this._inputElement.type = "search"; - this._inputElement.classList.add(ClassNames.asbInput); - this._inputElement.classList.add("win-textbox"); - this._inputElement.setAttribute("role", "textbox"); - this._inputElement.addEventListener("keydown", this._keyDownHandler.bind(this)); - this._inputElement.addEventListener("keypress", this._keyPressHandler.bind(this)); - this._inputElement.addEventListener("keyup", this._keyUpHandler.bind(this)); - this._inputElement.addEventListener("focus", this._inputFocusHandler.bind(this)); - this._inputElement.addEventListener("blur", this._inputBlurHandler.bind(this)); - this._inputElement.addEventListener("input", inputOrImeChangeHandler); - this._inputElement.addEventListener("compositionstart", inputOrImeChangeHandler); - this._inputElement.addEventListener("compositionupdate", inputOrImeChangeHandler); - this._inputElement.addEventListener("compositionend", inputOrImeChangeHandler); - _ElementUtilities._addEventListener(this._inputElement, "pointerdown", this._inputPointerDownHandler.bind(this)); - this._updateInputElementAriaLabel(); - this._element.appendChild(this._inputElement); - var context = this._tryGetInputContext(); - if (context) { - context.addEventListener("MSCandidateWindowShow", this._msCandidateWindowShowHandler.bind(this)); - context.addEventListener("MSCandidateWindowHide", this._msCandidateWindowHideHandler.bind(this)); - } - - // Flyout element - this._flyoutElement = _Global.document.createElement("div"); - this._flyoutElement.classList.add(ClassNames.asbFlyout); - this._flyoutElement.addEventListener("blur", this._flyoutBlurHandler.bind(this)); - _ElementUtilities._addEventListener(this._flyoutElement, "pointerup", flyoutPointerReleasedHandler); - _ElementUtilities._addEventListener(this._flyoutElement, "pointercancel", flyoutPointerReleasedHandler); - _ElementUtilities._addEventListener(this._flyoutElement, "pointerout", flyoutPointerReleasedHandler); - _ElementUtilities._addEventListener(this._flyoutElement, "pointerdown", this._flyoutPointerDownHandler.bind(this)); - this._element.appendChild(this._flyoutElement); - - // Repeater - var that = this; - function repeaterTemplate(suggestion) { - return that._renderSuggestion(suggestion); - } - this._suggestionsData = new BindingList.List(); - this._repeaterElement = _Global.document.createElement("div"); - this._repeater = new Repeater.Repeater(this._repeaterElement, { - data: this._suggestionsData, - template: repeaterTemplate, - }); - _ElementUtilities._ensureId(this._repeaterElement); - this._repeaterElement.setAttribute("role", "listbox"); - this._repeaterElement.setAttribute("aria-live", "polite"); - this._flyoutElement.appendChild(this._repeaterElement); - }, - - _setupSSM: function asb_setupSSM() { - // Get the search suggestion provider if it is available - this._suggestionManager = new _SuggestionManagerShim._SearchSuggestionManagerShim(); - this._suggestions = this._suggestionManager.suggestions; - - this._suggestions.addEventListener("vectorchanged", this._suggestionsChangedHandler); - this._suggestionManager.addEventListener("suggestionsrequested", this._suggestionsRequestedHandler); - }, - - // Flyout functions - _hideFlyout: function asb_hideFlyout() { - if (this._isFlyoutShown()) { - this._flyoutElement.style.display = "none"; - } - }, - - _showFlyout: function asb_showFlyout() { - var prevNumSuggestions = this._prevNumSuggestions || 0; - this._prevNumSuggestions = this._suggestionsData.length; - - if (this._isFlyoutShown() && prevNumSuggestions === this._suggestionsData.length) { - return; - } - - if (this._suggestionsData.length === 0) { - return; - } - - this._flyoutElement.style.display = "block"; - - var inputRect = this._inputElement.getBoundingClientRect(); - var flyoutRect = this._flyoutElement.getBoundingClientRect(); - var documentClientWidth = _Global.document.documentElement.clientWidth; - - // Display above vs below - the ASB flyout always opens in the direction where there is more space - var spaceAbove = inputRect.top; - var spaceBelow = _Global.document.documentElement.clientHeight - inputRect.bottom; - this._flyoutBelowInput = spaceBelow >= spaceAbove; - if (this._flyoutBelowInput) { - this._flyoutElement.classList.remove(ClassNames.asbFlyoutAbove); - this._flyoutElement.scrollTop = 0; - } else { - this._flyoutElement.classList.add(ClassNames.asbFlyoutAbove); - this._flyoutElement.scrollTop = this._flyoutElement.scrollHeight - this._flyoutElement.clientHeight; - } - - this._addFlyoutIMEPaddingIfRequired(); - - // Align left vs right edge - var alignRight; - if (_Global.getComputedStyle(this._flyoutElement).direction === "rtl") { - // RTL: Align to the right edge if there is enough space to the left of the control's - // right edge, or if there is not enough space to fit the flyout aligned to either edge. - alignRight = ((inputRect.right - flyoutRect.width) >= 0) || ((inputRect.left + flyoutRect.width) > documentClientWidth); - - } else { - // LTR: Align to the right edge if there isn't enough space to the right of the control's - // left edge, but there is enough space to the left of the control's right edge. - alignRight = ((inputRect.left + flyoutRect.width) > documentClientWidth) && ((inputRect.right - flyoutRect.width) >= 0); - } - - if (alignRight) { - this._flyoutElement.style.left = (inputRect.width - flyoutRect.width - this._element.clientLeft) + "px"; - } else { - this._flyoutElement.style.left = "-" + this._element.clientLeft + "px"; - } - - // ms-scroll-chaining:none will still chain scroll parent element if child div does - // not have a scroll bar. Prevent this by setting and updating touch action - this._flyoutElement.style.touchAction = this._flyoutElement.scrollHeight > flyoutRect.height ? "pan-y" : "none"; - - this._flyoutOpenPromise.cancel(); - var animationKeyframe = this._flyoutBelowInput ? "WinJS-flyoutBelowASB-showPopup" : "WinJS-flyoutAboveASB-showPopup"; - this._flyoutOpenPromise = Animations.showPopup(this._flyoutElement, { top: "0px", left: "0px", keyframe: animationKeyframe }); - }, - - _addFlyoutIMEPaddingIfRequired: function asb_addFlyoutIMEPaddingIfRequired() { - // Check if we have InputContext APIs - var context = this._tryGetInputContext(); - if (!context) { - return; - } - - // Check if flyout is visible and below input - if (!this._isFlyoutShown() || !this._flyoutBelowInput) { - return; - } - - // Check if IME is occluding flyout - var flyoutRect = this._flyoutElement.getBoundingClientRect(); - var imeRect = context.getCandidateWindowClientRect(); - var inputRect = this._inputElement.getBoundingClientRect(); - var flyoutTop = inputRect.bottom; - var flyoutBottom = inputRect.bottom + flyoutRect.height; - if (imeRect.top > flyoutBottom || imeRect.bottom < flyoutTop) { - return; - } - - // Shift the flyout down or to the right depending on IME/ASB width ratio. - // When the IME width is less than 45% of the ASB's width, the flyout gets - // shifted right, otherwise shifted down. - var animation = Animations.createRepositionAnimation(this._flyoutElement); - if (imeRect.width < (inputRect.width * 0.45)) { - this._flyoutElement.style.marginLeft = imeRect.width + "px"; - } else { - this._flyoutElement.style.marginTop = (imeRect.bottom - imeRect.top + 4) + "px"; - } - animation.execute(); - }, - - _findNextSuggestionElementIndex: function asb_findNextSuggestionElementIndex(curIndex) { - // Returns -1 if there are no focusable elements after curIndex - // Returns first element if curIndex < 0 - var startIndex = curIndex < 0 ? 0 : curIndex + 1; - for (var i = startIndex; i < this._suggestionsData.length; i++) { - if ((this._repeater.elementFromIndex(i)) && (this._isSuggestionSelectable(this._suggestionsData.getAt(i)))) { - return i; - } - } - return -1; - }, - - _findPreviousSuggestionElementIndex: function asb_findPreviousSuggestionElementIndex(curIndex) { - // Returns -1 if there are no focusable elements before curIndex - // Returns last element if curIndex >= suggestionsdata.length - var startIndex = curIndex >= this._suggestionsData.length ? this._suggestionsData.length - 1 : curIndex - 1; - for (var i = startIndex; i >= 0; i--) { - if ((this._repeater.elementFromIndex(i)) && (this._isSuggestionSelectable(this._suggestionsData.getAt(i)))) { - return i; - } - } - return -1; - }, - - _isFlyoutShown: function asb_isFlyoutShown() { - return (this._flyoutElement.style.display !== "none"); - }, - - _isSuggestionSelectable: function asb_isSuggestionSelectable(suggestion) { - return ((suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Query) || - (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Result)); - }, - - _processSuggestionChosen: function asb_processSuggestionChosen(item, event) { - this.queryText = item.text; - if (item.kind === _SuggestionManagerShim._SearchSuggestionKind.Query) { - this._submitQuery(item.text, false /*fillLinguisticDetails*/, event); // force empty linguistic details since explicitly chosen suggestion from list - } else if (item.kind === _SuggestionManagerShim._SearchSuggestionKind.Result) { - this._fireEvent(EventNames.resultsuggestionchosen, { - tag: item.tag, - keyModifiers: getKeyModifiers(event), - storageFile: null - }); - } - this._hideFlyout(); - }, - - _selectSuggestionAtIndex: function asb_selectSuggestionAtIndex(indexToSelect) { - var that = this; - function scrollToView(targetElement) { - var popupHeight = that._flyoutElement.getBoundingClientRect().bottom - that._flyoutElement.getBoundingClientRect().top; - if ((targetElement.offsetTop + targetElement.offsetHeight) > (that._flyoutElement.scrollTop + popupHeight)) { - // Element to scroll is below popup visible area - var scrollDifference = (targetElement.offsetTop + targetElement.offsetHeight) - (that._flyoutElement.scrollTop + popupHeight); - _ElementUtilities._zoomTo(that._flyoutElement, { contentX: 0, contentY: (that._flyoutElement.scrollTop + scrollDifference), viewportX: 0, viewportY: 0 }); - } else if (targetElement.offsetTop < that._flyoutElement.scrollTop) { - // Element to scroll is above popup visible area - _ElementUtilities._zoomTo(that._flyoutElement, { contentX: 0, contentY: targetElement.offsetTop, viewportX: 0, viewportY: 0 }); - } - } - - // Sets focus on the specified element and removes focus from others. - // Clears selection if index is outside of suggestiondata index range. - var curElement = null; - for (var i = 0; i < this._suggestionsData.length; i++) { - curElement = this._repeater.elementFromIndex(i); - if (i !== indexToSelect) { - curElement.classList.remove(ClassNames.asbSuggestionSelected); - curElement.setAttribute("aria-selected", "false"); - } else { - curElement.classList.add(ClassNames.asbSuggestionSelected); - scrollToView(curElement); - curElement.setAttribute("aria-selected", "true"); - } - } - this._currentSelectedIndex = indexToSelect; - if (curElement) { - this._inputElement.setAttribute("aria-activedescendant", this._repeaterElement.id + indexToSelect); - } else if (this._inputElement.hasAttribute("aria-activedescendant")) { - this._inputElement.removeAttribute("aria-activedescendant"); - } - }, - - _updateFakeFocus: function asb_updateFakeFocus() { - var firstElementIndex; - if (this._isFlyoutShown() && (this._chooseSuggestionOnEnter)) { - firstElementIndex = this._findNextSuggestionElementIndex(-1); - } else { - // This will clear the fake focus. - firstElementIndex = -1; - } - - this._selectSuggestionAtIndex(firstElementIndex); - }, - - _updateQueryTextWithSuggestionText: function asb_updateQueryTextWithSuggestionText(suggestionIndex) { - if ((suggestionIndex >= 0) && (suggestionIndex < this._suggestionsData.length)) { - this.queryText = this._suggestionsData.getAt(suggestionIndex).text; - } - }, - - // Helpers - _disableControl: function asb_disableControl() { - if (this._isFlyoutShown()) { - this._hideFlyout(); - } - this._element.disabled = true; - this._element.classList.add(ClassNames.asbDisabled); - this._inputElement.disabled = true; - }, - - _enableControl: function asb_enableControl() { - this._element.disabled = false; - this._element.classList.remove(ClassNames.asbDisabled); - this._inputElement.disabled = false; - if (_Global.document.activeElement === this._element) { - _ElementUtilities._setActive(this._inputElement); - } - }, - - _fireEvent: function asb_fireEvent(type, detail) { - // Returns true if ev.preventDefault() was not called - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(type, true, true, detail); - return this._element.dispatchEvent(event); - }, - - _getLinguisticDetails: function asb_getLinguisticDetails(useCache, createFilled) { // createFilled=false always creates an empty linguistic details object, otherwise generate it or use the cache - function createQueryLinguisticDetails(compositionAlternatives, compositionStartOffset, compositionLength, queryTextPrefix, queryTextSuffix) { - var linguisticDetails = null; - - // The linguistic alternatives we receive are only for the composition string being composed. We need to provide the linguistic alternatives - // in the form of the full query text with alternatives embedded. - var fullCompositionAlternatives = []; - for (var i = 0; i < compositionAlternatives.length; i++) { - fullCompositionAlternatives[i] = queryTextPrefix + compositionAlternatives[i] + queryTextSuffix; - } - - if (_WinRT.Windows.ApplicationModel.Search.SearchQueryLinguisticDetails) { - try { - linguisticDetails = new _WinRT.Windows.ApplicationModel.Search.SearchQueryLinguisticDetails(fullCompositionAlternatives, compositionStartOffset, compositionLength); - } catch (e) { - // WP10 currently exposes SQLD API but throws on instantiation. - } - } - - if (!linguisticDetails) { - // If we're in web compartment, create a script version of the WinRT SearchQueryLinguisticDetails object - linguisticDetails = { - queryTextAlternatives: fullCompositionAlternatives, - queryTextCompositionStart: compositionStartOffset, - queryTextCompositionLength: compositionLength - }; - } - return linguisticDetails; - } - - var linguisticDetails = null; - if ((this._inputElement.value === this._prevQueryText) && useCache && this._prevLinguisticDetails && createFilled) { - linguisticDetails = this._prevLinguisticDetails; - } else { - var compositionAlternatives = []; - var compositionStartOffset = 0; - var compositionLength = 0; - var queryTextPrefix = ""; - var queryTextSuffix = ""; - if (createFilled) { - var context = this._tryGetInputContext(); - if (context && context.getCompositionAlternatives) { - compositionAlternatives = context.getCompositionAlternatives(); - compositionStartOffset = context.compositionStartOffset; - compositionLength = context.compositionEndOffset - context.compositionStartOffset; - - if ((this._inputElement.value !== this._prevQueryText) || (this._prevCompositionLength === 0) || (compositionLength > 0)) { - queryTextPrefix = this._inputElement.value.substring(0, compositionStartOffset); - queryTextSuffix = this._inputElement.value.substring(compositionStartOffset + compositionLength); - } else { - // composition ended, but alternatives have been kept, need to reuse the previous query prefix/suffix, but still report to the client that the composition has ended (start & length of composition of 0) - queryTextPrefix = this._inputElement.value.substring(0, this._prevCompositionStart); - queryTextSuffix = this._inputElement.value.substring(this._prevCompositionStart + this._prevCompositionLength); - } - } - } - linguisticDetails = createQueryLinguisticDetails(compositionAlternatives, compositionStartOffset, compositionLength, queryTextPrefix, queryTextSuffix); - } - return linguisticDetails; - }, - - _isElementInSearchControl: function asb_isElementInSearchControl(targetElement) { - return this.element.contains(targetElement) || (this.element === targetElement); - }, - - _renderSuggestion: function asb_renderSuggestion(suggestion) { - var root = null; - if (!suggestion) { - return root; - } - if (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Query) { - root = querySuggestionRenderer(this, suggestion); - } else if (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Separator) { - root = separatorSuggestionRenderer(suggestion); - } else if (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Result) { - root = resultSuggestionRenderer(this, suggestion); - } else { - throw new _ErrorFromName("WinJS.UI.AutoSuggestBox.invalidSuggestionKind", Strings.invalidSuggestionKind); - } - return root; - }, - - _shouldIgnoreInput: function asb_shouldIgnoreInput() { - var processingIMEFocusLossKey = this._isProcessingDownKey || this._isProcessingUpKey || this._isProcessingTabKey || this._isProcessingEnterKey; - return processingIMEFocusLossKey || this._isFlyoutPointerDown; - }, - - _submitQuery: function asb_submitQuery(queryText, fillLinguisticDetails, event) { - if (this._disposed) { - return; - } - - // get the most up to date value of the input langauge from WinRT if available - if (_WinRT.Windows.Globalization.Language) { - this._lastKeyPressLanguage = _WinRT.Windows.Globalization.Language.currentInputMethodLanguageTag; - } - - this._fireEvent(EventNames.querysubmitted, { - language: this._lastKeyPressLanguage, - linguisticDetails: this._getLinguisticDetails(true /*useCache*/, fillLinguisticDetails), // allow caching, but generate empty linguistic details if suggestion is used - queryText: queryText, - keyModifiers: getKeyModifiers(event) - }); - - if (this._suggestionManager) { - this._suggestionManager.addToHistory(this._inputElement.value, this._lastKeyPressLanguage); - } - }, - - _tryGetInputContext: function asb_tryGetInputContext() { - // On WP, msGetInputContext is defined but throws when invoked - if (this._inputElement.msGetInputContext) { - try { - return this._inputElement.msGetInputContext(); - } catch (e) { - return null; - } - } - return null; - }, - - _updateInputElementAriaLabel: function asb_updateInputElementAriaLabel() { - this._inputElement.setAttribute("aria-label", - this._inputElement.placeholder ? _Resources._formatString(Strings.ariaLabelInputPlaceHolder, this._inputElement.placeholder) : Strings.ariaLabelInputNoPlaceHolder - ); - }, - - // Event Handlers - _flyoutBlurHandler: function asb_flyoutBlurHandler(event) { - if (this._isElementInSearchControl(_Global.document.activeElement)) { - this._internalFocusMove = true; - } else { - this._element.classList.remove(ClassNames.asbInputFocus); - this._hideFlyout(); - } - }, - - _flyoutPointerDownHandler: function asb_flyoutPointerDownHandler(ev) { - var that = this; - var srcElement = ev.target; - function findSuggestionElementIndex() { - if (srcElement) { - for (var i = 0; i < that._suggestionsData.length; i++) { - if (that._repeater.elementFromIndex(i) === srcElement) { - return i; - } - } - } - return -1; - } - - this._isFlyoutPointerDown = true; - while (srcElement && (srcElement.parentNode !== this._repeaterElement)) { - srcElement = srcElement.parentNode; - } - var index = findSuggestionElementIndex(); - if ((index >= 0) && (index < this._suggestionsData.length) && (this._currentFocusedIndex !== index)) { - if (this._isSuggestionSelectable(this._suggestionsData.getAt(index))) { - this._currentFocusedIndex = index; - this._selectSuggestionAtIndex(index); - this._updateQueryTextWithSuggestionText(this._currentFocusedIndex); - } - } - // Prevent default so focus does not leave input element. - ev.preventDefault(); - }, - - _flyoutPointerReleasedHandler: function asb_flyoutPointerReleasedHandler() { - this._isFlyoutPointerDown = false; - - if (this._reflowImeOnPointerRelease) { - this._reflowImeOnPointerRelease = false; - var animation = Animations.createRepositionAnimation(this._flyoutElement); - this._flyoutElement.style.marginTop = ""; - this._flyoutElement.style.marginLeft = ""; - animation.execute(); - } - }, - - _inputBlurHandler: function asb_inputBlurHandler(event) { - // Hide flyout if focus is leaving the control - if (!this._isElementInSearchControl(_Global.document.activeElement)) { - this._element.classList.remove(ClassNames.asbInputFocus); - this._hideFlyout(); - } - this.queryText = this._prevQueryText; // Finalize IME composition - this._isProcessingDownKey = false; - this._isProcessingUpKey = false; - this._isProcessingTabKey = false; - this._isProcessingEnterKey = false; - }, - - _inputFocusHandler: function asb_inputFocusHandler(event) { - // Refresh hit highlighting if text has changed since focus was present - // This can happen if the user committed a suggestion previously. - if (this._inputElement.value !== this._prevQueryText) { - if (_WinRT.Windows.Data.Text.SemanticTextQuery) { - if (this._inputElement.value !== "") { - this._hitFinder = new _WinRT.Windows.Data.Text.SemanticTextQuery(this._inputElement.value, this._inputElement.lang); - } else { - this._hitFinder = null; - } - } - } - - // If focus is returning to the input box from outside the control, show the flyout and refresh the suggestions - if (event.target === this._inputElement && !this._internalFocusMove) { - this._showFlyout(); - if (this._currentFocusedIndex !== -1) { - // Focus is not in input - this._selectSuggestionAtIndex(this._currentFocusedIndex); - } else { - this._updateFakeFocus(); - } - - this._suggestionManager.setQuery( - this._inputElement.value, - this._lastKeyPressLanguage, - this._getLinguisticDetails(true /*useCache*/, true /*createFilled*/) - ); - } - - this._internalFocusMove = false; - this._element.classList.add(ClassNames.asbInputFocus); - }, - - _inputOrImeChangeHandler: function asb_inputImeChangeHandler() { - var that = this; - function hasLinguisticDetailsChanged(newLinguisticDetails) { - var hasLinguisticDetailsChanged = false; - if ((that._prevLinguisticDetails.queryTextCompositionStart !== newLinguisticDetails.queryTextCompositionStart) || - (that._prevLinguisticDetails.queryTextCompositionLength !== newLinguisticDetails.queryTextCompositionLength) || - (that._prevLinguisticDetails.queryTextAlternatives.length !== newLinguisticDetails.queryTextAlternatives.length)) { - hasLinguisticDetailsChanged = true; - } - that._prevLinguisticDetails = newLinguisticDetails; - return hasLinguisticDetailsChanged; - } - - // swallow the IME change event that gets fired when composition is ended due to keyboarding down to the suggestion list & mouse down on the button - if (!this._shouldIgnoreInput()) { - var linguisticDetails = this._getLinguisticDetails(false /*useCache*/, true /*createFilled*/); // never cache on explicit user changes - var hasLinguisticDetailsChanged = hasLinguisticDetailsChanged(linguisticDetails); // updates this._prevLinguisticDetails - - // Keep the previous composition cache up to date, execpt when composition ended with no text change and alternatives are kept. - // In that case, we need to use the cached values to correctly generate the query prefix/suffix for substituting alternatives, but still report to the client that the composition has ended (via start & length of composition of 0) - if ((this._inputElement.value !== this._prevQueryText) || (this._prevCompositionLength === 0) || (linguisticDetails.queryTextCompositionLength > 0)) { - this._prevCompositionStart = linguisticDetails.queryTextCompositionStart; - this._prevCompositionLength = linguisticDetails.queryTextCompositionLength; - } - - if ((this._prevQueryText === this._inputElement.value) && !hasLinguisticDetailsChanged) { - // Sometimes the input change is fired even if there is no change in input. - // Swallow event in those cases. - return; - } - this._prevQueryText = this._inputElement.value; - - // get the most up to date value of the input langauge from WinRT if available - if (_WinRT.Windows.Globalization.Language) { - this._lastKeyPressLanguage = _WinRT.Windows.Globalization.Language.currentInputMethodLanguageTag; - } - - if (_WinRT.Windows.Data.Text.SemanticTextQuery) { - if (this._inputElement.value !== "") { - this._hitFinder = new _WinRT.Windows.Data.Text.SemanticTextQuery(this._inputElement.value, this._lastKeyPressLanguage); - } else { - this._hitFinder = null; - } - } - - this._fireEvent(EventNames.querychanged, { - language: this._lastKeyPressLanguage, - queryText: this._inputElement.value, - linguisticDetails: linguisticDetails - }); - - this._suggestionManager.setQuery( - this._inputElement.value, - this._lastKeyPressLanguage, - linguisticDetails - ); - } - }, - - _inputPointerDownHandler: function asb_inputPointerDownHandler() { - if ((_Global.document.activeElement === this._inputElement) && (this._currentSelectedIndex !== -1)) { - this._currentFocusedIndex = -1; - this._selectSuggestionAtIndex(this._currentFocusedIndex); - } - }, - - _keyDownHandler: function asb_keyDownHandler(event) { - var that = this; - function setSelection(index) { - that._currentFocusedIndex = index; - that._selectSuggestionAtIndex(index); - event.preventDefault(); - event.stopPropagation(); - } - - this._lastKeyPressLanguage = event.locale; - if (event.keyCode === Key.tab) { - this._isProcessingTabKey = true; - } else if (event.keyCode === Key.upArrow) { - this._isProcessingUpKey = true; - } else if (event.keyCode === Key.downArrow) { - this._isProcessingDownKey = true; - } else if ((event.keyCode === Key.enter) && (event.locale === "ko")) { - this._isProcessingEnterKey = true; - } - // Ignore keys handled by ime. - if (event.keyCode !== Key.IME) { - if (event.keyCode === Key.tab) { - var closeFlyout = true; - if (event.shiftKey) { - if (this._currentFocusedIndex !== -1) { - // Focus is not in input - setSelection(-1); - closeFlyout = false; - } - } else if (this._currentFocusedIndex === -1) { - this._currentFocusedIndex = - this._flyoutBelowInput - ? this._findNextSuggestionElementIndex(this._currentFocusedIndex) - : this._findPreviousSuggestionElementIndex(this._suggestionsData.length); - if (this._currentFocusedIndex !== -1) { - // Found a selectable element - setSelection(this._currentFocusedIndex); - this._updateQueryTextWithSuggestionText(this._currentFocusedIndex); - closeFlyout = false; - } - } - - if (closeFlyout) { - this._hideFlyout(); - } - } else if (event.keyCode === Key.escape) { - if (this._currentFocusedIndex !== -1) { - // Focus is not in input - this.queryText = this._prevQueryText; - setSelection(-1); - } else if (this.queryText !== "") { - this.queryText = ""; - this._inputOrImeChangeHandler(null); - event.preventDefault(); - event.stopPropagation(); - } - } else if ((this._flyoutBelowInput && event.keyCode === Key.upArrow) || (!this._flyoutBelowInput && event.keyCode === Key.downArrow)) { - var prevIndex; - if (this._currentSelectedIndex !== -1) { - prevIndex = this._findPreviousSuggestionElementIndex(this._currentSelectedIndex); - // Restore user entered query when user navigates back to input. - if (prevIndex === -1) { - this.queryText = this._prevQueryText; - } - } else { - prevIndex = this._findPreviousSuggestionElementIndex(this._suggestionsData.length); - } - setSelection(prevIndex); - this._updateQueryTextWithSuggestionText(this._currentFocusedIndex); - } else if ((this._flyoutBelowInput && event.keyCode === Key.downArrow) || (!this._flyoutBelowInput && event.keyCode === Key.upArrow)) { - var nextIndex = this._findNextSuggestionElementIndex(this._currentSelectedIndex); - // Restore user entered query when user navigates back to input. - if ((this._currentSelectedIndex !== -1) && (nextIndex === -1)) { - this.queryText = this._prevQueryText; - } - setSelection(nextIndex); - this._updateQueryTextWithSuggestionText(this._currentFocusedIndex); - } else if (event.keyCode === Key.enter) { - if (this._currentSelectedIndex === -1) { - this._submitQuery(this._inputElement.value, true /*fillLinguisticDetails*/, event); - } else { - this._processSuggestionChosen(this._suggestionsData.getAt(this._currentSelectedIndex), event); - } - this._hideFlyout(); - } - } - }, - - _keyUpHandler: function asb_keyUpHandler(event) { - if (event.keyCode === Key.tab) { - this._isProcessingTabKey = false; - } else if (event.keyCode === Key.upArrow) { - this._isProcessingUpKey = false; - } else if (event.keyCode === Key.downArrow) { - this._isProcessingDownKey = false; - } else if (event.keyCode === Key.enter) { - this._isProcessingEnterKey = false; - } - }, - - _keyPressHandler: function asb_keyPressHandler(event) { - this._lastKeyPressLanguage = event.locale; - }, - - _msCandidateWindowHideHandler: function asb_msCandidateWindowHideHandler() { - if (!this._isFlyoutPointerDown) { - var animation = Animations.createRepositionAnimation(this._flyoutElement); - this._flyoutElement.style.marginTop = ""; - this._flyoutElement.style.marginLeft = ""; - animation.execute(); - } else { - this._reflowImeOnPointerRelease = true; - } - }, - - _msCandidateWindowShowHandler: function asb_msCandidateWindowShowHandler() { - this._addFlyoutIMEPaddingIfRequired(); - this._reflowImeOnPointerRelease = false; - }, - - _suggestionsChangedHandler: function asb_suggestionsChangedHandler(event) { - var collectionChange = event.collectionChange || event.detail.collectionChange; - var changeIndex = (+event.index === event.index) ? event.index : event.detail.index; - var ChangeEnum = _SuggestionManagerShim._CollectionChange; - if (collectionChange === ChangeEnum.reset) { - if (this._isFlyoutShown()) { - this._hideFlyout(); - } - this._suggestionsData.splice(0, this._suggestionsData.length); - } else if (collectionChange === ChangeEnum.itemInserted) { - var suggestion = this._suggestions[changeIndex]; - this._suggestionsData.splice(changeIndex, 0, suggestion); - - this._showFlyout(); - - } else if (collectionChange === ChangeEnum.itemRemoved) { - if ((this._suggestionsData.length === 1)) { - _ElementUtilities._setActive(this._inputElement); - - this._hideFlyout(); - } - this._suggestionsData.splice(changeIndex, 1); - } else if (collectionChange === ChangeEnum.itemChanged) { - var suggestion = this._suggestions[changeIndex]; - if (suggestion !== this._suggestionsData.getAt(changeIndex)) { - this._suggestionsData.setAt(changeIndex, suggestion); - } else { - // If the suggestions manager gives us an identical item, it means that only the hit highlighted text has changed. - var existingElement = this._repeater.elementFromIndex(changeIndex); - if (_ElementUtilities.hasClass(existingElement, ClassNames.asbSuggestionQuery)) { - addHitHighlightedText(existingElement, suggestion, suggestion.text); - } else { - var resultSuggestionDiv = existingElement.querySelector("." + ClassNames.asbSuggestionResultText); - if (resultSuggestionDiv) { - addHitHighlightedText(resultSuggestionDiv, suggestion, suggestion.text); - var resultSuggestionDetailDiv = existingElement.querySelector("." + ClassNames.asbSuggestionResultDetailedText); - if (resultSuggestionDetailDiv) { - addHitHighlightedText(resultSuggestionDetailDiv, suggestion, suggestion.detailText); - } - } - } - } - } - - if (_Global.document.activeElement === this._inputElement) { - this._updateFakeFocus(); - } - }, - - _suggestionsRequestedHandler: function asb_suggestionsRequestedHandler(event) { - // get the most up to date value of the input langauge from WinRT if available - if (_WinRT.Windows.Globalization.Language) { - this._lastKeyPressLanguage = _WinRT.Windows.Globalization.Language.currentInputMethodLanguageTag; - } - - var request = event.request || event.detail.request; - var deferral; - this._fireEvent(EventNames.suggestionsrequested, { - setPromise: function (promise) { - deferral = request.getDeferral(); - promise.then(function () { - deferral.complete(); - }); - }, - searchSuggestionCollection: request.searchSuggestionCollection, - language: this._lastKeyPressLanguage, - linguisticDetails: this._getLinguisticDetails(true /*useCache*/, true /*createFilled*/), - queryText: this._inputElement.value - }); - }, - }, { - createResultSuggestionImage: function asb_createResultSuggestionImage(url) { - /// - /// - /// Creates the image argument for SearchSuggestionCollection.appendResultSuggestion. - /// - /// - /// The url of the image. - /// - /// - /// - if (_WinRT.Windows.Foundation.Uri && _WinRT.Windows.Storage.Streams.RandomAccessStreamReference) { - return _WinRT.Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(new _WinRT.Windows.Foundation.Uri(url)); - } - return url; - }, - - _EventNames: EventNames, - - _sortAndMergeHits: function asb_sortAndMergeHits(hitsProvided) { - function hitStartPositionAscendingSorter(firstHit, secondHit) { - var returnValue = 0; - if (firstHit.startPosition < secondHit.startPosition) { - returnValue = -1; - } else if (firstHit.startPosition > secondHit.startPosition) { - returnValue = 1; - } - return returnValue; - } - function hitIntersectionReducer(reducedHits, nextHit, currentIndex) { - if (currentIndex === 0) { - reducedHits.push(nextHit); - } else { - var curHit = reducedHits[reducedHits.length - 1]; - var curHitEndPosition = curHit.startPosition + curHit.length; - if (nextHit.startPosition <= curHitEndPosition) { - // The next hit intersects or is next to current hit. Merge it. - var nextHitEndPosition = nextHit.startPosition + nextHit.length; - if (nextHitEndPosition > curHitEndPosition) { - curHit.length = nextHitEndPosition - curHit.startPosition; - } - } else { - // No intersection, simply add to reduced list. - reducedHits.push(nextHit); - } - } - return reducedHits; - } - - var reducedHits = []; - if (hitsProvided) { - // Copy hitsprovided array as winrt objects are immutable. - var hits = new Array(hitsProvided.length); - for (var i = 0; i < hitsProvided.length; i++) { - hits.push({ startPosition: hitsProvided[i].startPosition, length: hitsProvided[i].length }); - } - hits.sort(hitStartPositionAscendingSorter); - hits.reduce(hitIntersectionReducer, reducedHits); - } - return reducedHits; - } - }); - - function addHitHighlightedText(element, item, text, hitFinder) { - function addNewSpan(element, textContent, insertBefore) { - // Adds new span element with specified inner text as child to element, placed before insertBefore - var spanElement = _Global.document.createElement("span"); - spanElement.textContent = textContent; - spanElement.setAttribute("aria-hidden", "true"); - spanElement.classList.add(ClassNames.asbHitHighlightSpan); - element.insertBefore(spanElement, insertBefore); - return spanElement; - } - - if (text) { - // Remove any existing hit highlighted text spans - _ElementListUtilities.query("." + ClassNames.asbHitHighlightSpan, element).forEach(function (childElement) { - childElement.parentNode.removeChild(childElement); - }); - - // Insert spans at the front of element - var firstChild = element.firstChild; - - var hitsProvided = item.hits; - if ((!hitsProvided) && (hitFinder) && (item.kind !== _SuggestionManagerShim._SearchSuggestionKind.Separator)) { - hitsProvided = hitFinder.find(text); - } - - var hits = AutoSuggestBox._sortAndMergeHits(hitsProvided); - - var lastPosition = 0; - for (var i = 0; i < hits.length; i++) { - var hit = hits[i]; - - // Add previous normal text - addNewSpan(element, text.substring(lastPosition, hit.startPosition), firstChild); - - lastPosition = hit.startPosition + hit.length; - - // Add hit highlighted text - var spanHitHighlightedText = addNewSpan(element, text.substring(hit.startPosition, lastPosition), firstChild); - _ElementUtilities.addClass(spanHitHighlightedText, ClassNames.asbBoxFlyoutHighlightText); - } - - // Add final normal text - if (lastPosition < text.length) { - addNewSpan(element, text.substring(lastPosition), firstChild); - } - } - } - - function getKeyModifiers(ev) { - // Returns the same value as https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.system.virtualkeymodifiers - var VirtualKeys = { - ctrlKey: 1, - altKey: 2, - shiftKey: 4 - }; - - var keyModifiers = 0; - if (ev.ctrlKey) { - keyModifiers |= VirtualKeys.ctrlKey; - } - if (ev.altKey) { - keyModifiers |= VirtualKeys.altKey; - } - if (ev.shiftKey) { - keyModifiers |= VirtualKeys.shiftKey; - } - return keyModifiers; - } - - function resultSuggestionRenderer(asb, item) { - function handleInvoke(e) { - asb._internalFocusMove = true; - asb._inputElement.focus(); - asb._processSuggestionChosen(item, e); - } - - var root = _Global.document.createElement("div"); - var image = new _Global.Image(); - image.style.opacity = 0; - var loadImage = function (url) { - function onload() { - image.removeEventListener("load", onload, false); - Animations.fadeIn(image); - } - image.addEventListener("load", onload, false); - image.src = url; - }; - - if (item.image !== null) { - item.image.openReadAsync().then(function (streamWithContentType) { - if (streamWithContentType !== null) { - loadImage(_Global.URL.createObjectURL(streamWithContentType, { oneTimeOnly: true })); - } - }); - } else if (item.imageUrl !== null) { - loadImage(item.imageUrl); - } - image.setAttribute("aria-hidden", "true"); - root.appendChild(image); - - var divElement = _Global.document.createElement("div"); - _ElementUtilities.addClass(divElement, ClassNames.asbSuggestionResultText); - addHitHighlightedText(divElement, item, item.text); - divElement.title = item.text; - divElement.setAttribute("aria-hidden", "true"); - root.appendChild(divElement); - - var brElement = _Global.document.createElement("br"); - divElement.appendChild(brElement); - - var divDetailElement = _Global.document.createElement("span"); - _ElementUtilities.addClass(divDetailElement, ClassNames.asbSuggestionResultDetailedText); - addHitHighlightedText(divDetailElement, item, item.detailText); - divDetailElement.title = item.detailText; - divDetailElement.setAttribute("aria-hidden", "true"); - divElement.appendChild(divDetailElement); - - _ElementUtilities.addClass(root, ClassNames.asbSuggestionResult); - - _ElementUtilities._addEventListener(root, "click", function (e) { - if (!asb._isFlyoutPointerDown) { - handleInvoke(e); - } - }); - _ElementUtilities._addEventListener(root, "pointerup", handleInvoke); - - root.setAttribute("role", "option"); - var ariaLabel = _Resources._formatString(Strings.ariaLabelResult, item.text, item.detailText); - root.setAttribute("aria-label", ariaLabel); - return root; - } - - function querySuggestionRenderer(asb, item) { - function handleInvoke(e) { - asb._internalFocusMove = true; - asb._inputElement.focus(); - asb._processSuggestionChosen(item, e); - } - - var root = _Global.document.createElement("div"); - - addHitHighlightedText(root, item, item.text); - root.title = item.text; - - root.classList.add(ClassNames.asbSuggestionQuery); - - _ElementUtilities._addEventListener(root, "click", function (e) { - if (!asb._isFlyoutPointerDown) { - handleInvoke(e); - } - }); - _ElementUtilities._addEventListener(root, "pointerup", handleInvoke); - - var ariaLabel = _Resources._formatString(Strings.ariaLabelQuery, item.text); - root.setAttribute("role", "option"); - root.setAttribute("aria-label", ariaLabel); - - return root; - } - - function separatorSuggestionRenderer(item) { - var root = _Global.document.createElement("div"); - if (item.text.length > 0) { - var textElement = _Global.document.createElement("div"); - textElement.textContent = item.text; - textElement.title = item.text; - textElement.setAttribute("aria-hidden", "true"); - root.appendChild(textElement); - } - root.insertAdjacentHTML("beforeend", "
"); - _ElementUtilities.addClass(root, ClassNames.asbSuggestionSeparator); - root.setAttribute("role", "separator"); - var ariaLabel = _Resources._formatString(Strings.ariaLabelSeparator, item.text); - root.setAttribute("aria-label", ariaLabel); - return root; - } - - _Base.Class.mix(AutoSuggestBox, _Control.DOMEventMixin); - return AutoSuggestBox; - }) - }); - exports.ClassNames = ClassNames; -}); - - -define('require-style!less/styles-searchbox',[],function(){}); - -define('require-style!less/colors-searchbox',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/SearchBox',[ - '../Core/_Global', - '../Core/_WinRT', - '../Core/_Base', - '../Core/_ErrorFromName', - '../Core/_Events', - '../Core/_Resources', - './AutoSuggestBox', - '../_Accents', - '../Utilities/_Control', - '../Utilities/_ElementUtilities', - './AutoSuggestBox/_SearchSuggestionManagerShim', - '../Application', - 'require-style!less/styles-searchbox', - 'require-style!less/colors-searchbox' -], function searchboxInit(_Global, _WinRT, _Base, _ErrorFromName, _Events, _Resources, AutoSuggestBox, _Accents, _Control, _ElementUtilities, _SuggestionManagerShim, Application) { - "use strict"; - - _Accents.createAccentRule("html.win-hoverable .win-searchbox-button:not(.win-searchbox-button-disabled):hover", [{ name: "color", value: _Accents.ColorTypes.accent }, ]); - _Accents.createAccentRule(".win-searchbox-button.win-searchbox-button:not(.win-searchbox-button-disabled):hover:active", [{ name: "background-color", value: _Accents.ColorTypes.accent }, ]); - - _Base.Namespace.define("WinJS.UI", { - /// - /// - /// Enables the user to perform search queries and select suggestions. - /// - /// - /// - /// - /// - /// ]]> - /// - /// Raised when the app automatically redirects focus to the search box. This event can only be raised when the focusOnKeyboardInput property is set to true. - /// - /// Styles the entire Search box control. - /// Styles the query input box. - /// Styles the search button. - /// Styles the result suggestions flyout. - /// Styles the result type suggestion. - /// Styles the query type suggestion. - /// - /// Styles the separator type suggestion. - /// - /// - /// Styles the currently selected suggestion. - /// - /// - /// - SearchBox: _Base.Namespace._lazy(function () { - - // Enums - var ClassName = { - searchBox: "win-searchbox", - searchBoxDisabled: "win-searchbox-disabled", - searchBoxInput: "win-searchbox-input", - searchBoxInputFocus: "win-searchbox-input-focus", - searchBoxButton: "win-searchbox-button", - searchBoxFlyout: "win-searchbox-flyout", - searchBoxFlyoutHighlightText: "win-searchbox-flyout-highlighttext", - searchBoxHitHighlightSpan: "win-searchbox-hithighlight-span", - searchBoxSuggestionResult: "win-searchbox-suggestion-result", - searchBoxSuggestionResultText: "win-searchbox-suggestion-result-text", - searchBoxSuggestionResultDetailedText: "win-searchbox-suggestion-result-detailed-text", - searchBoxSuggestionSelected: "win-searchbox-suggestion-selected", - searchBoxSuggestionQuery: "win-searchbox-suggestion-query", - searchBoxSuggestionSeparator: "win-searchbox-suggestion-separator", - searchBoxButtonInputFocus: "win-searchbox-button-input-focus", - searchBoxButtonDisabled: "win-searchbox-button-disabled" - }; - - var EventName = { - receivingfocusonkeyboardinput: "receivingfocusonkeyboardinput" - }; - - var strings = { - get invalidSearchBoxSuggestionKind() { return "Error: Invalid search suggestion kind."; }, - get ariaLabel() { return _Resources._getWinJSString("ui/searchBoxAriaLabel").value; }, - get ariaLabelInputNoPlaceHolder() { return _Resources._getWinJSString("ui/searchBoxAriaLabelInputNoPlaceHolder").value; }, - get ariaLabelInputPlaceHolder() { return _Resources._getWinJSString("ui/searchBoxAriaLabelInputPlaceHolder").value; }, - get searchBoxDeprecated() { return "SearchBox is deprecated and may not be available in future releases. Instead use AutoSuggestBox."; } - }; - - var SearchBox = _Base.Class.derive(AutoSuggestBox.AutoSuggestBox, function SearchBox_ctor(element, options) { - /// - /// - /// Creates a new SearchBox. - /// - /// - /// The DOM element that hosts the SearchBox. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the querychanged event, - /// add a property named "onquerychanged" to the options object and set its value to the event handler. - /// This parameter is optional. - /// - /// - /// The new SearchBox. - /// - /// - /// SearchBox is deprecated and may not be available in future releases. Instead use AutoSuggestBox. - /// - /// - /// - - _ElementUtilities._deprecated(strings.searchBoxDeprecated); - - this._requestingFocusOnKeyboardInputHandlerBind = this._requestingFocusOnKeyboardInputHandler.bind(this); - - // Elements - this._buttonElement = _Global.document.createElement("div"); - - // Variables - this._focusOnKeyboardInput = false; - - // Calling the super constructor - since the super constructor processes the options, - // any property setter at this point must be functional. - AutoSuggestBox.AutoSuggestBox.call(this, element, options); - - // Add SearchBox classes to DOM elements - this.element.classList.add(ClassName.searchBox); - this._flyoutElement.classList.add(ClassName.searchBoxFlyout); - - this._inputElement.classList.add(ClassName.searchBoxInput); - this._inputElement.addEventListener("blur", this._searchboxInputBlurHandler.bind(this)); - this._inputElement.addEventListener("focus", this._searchboxInputFocusHandler.bind(this)); - - this._buttonElement.tabIndex = -1; - this._buttonElement.classList.add(ClassName.searchBoxButton); - this._buttonElement.addEventListener("click", this._buttonClickHandler.bind(this)); - _ElementUtilities._addEventListener(this._buttonElement, "pointerdown", this._buttonPointerDownHandler.bind(this)); - this.element.appendChild(this._buttonElement); - }, { - /// - /// Enable automatically focusing the search box when the user types into the app window (off by default) While this is enabled, - /// input on the current thread will be intercepted and redirected to the search box. Only textual input will trigger the search box to focus. - /// The caller will continue to receive non-text keys (such as arrows, tab, etc - /// This will also not affect WIN/CTRL/ALT key combinations (except for Ctrl-V for paste). - /// If the client needs more to happen than just set focus in the box (make control visible, etc.), they will need to handle the event. - /// If enabled, the app must be sure to disable this if the user puts focus in some other edit field. - /// - /// - focusOnKeyboardInput: { - get: function () { - return this._focusOnKeyboardInput; - }, - set: function (value) { - if (this._focusOnKeyboardInput && !value) { - Application._applicationListener.removeEventListener(this.element, "requestingfocusonkeyboardinput", this._requestingFocusOnKeyboardInputHandlerBind); - } else if (!this._focusOnKeyboardInput && !!value) { - Application._applicationListener.addEventListener(this.element, "requestingfocusonkeyboardinput", this._requestingFocusOnKeyboardInputHandlerBind); - } - this._focusOnKeyboardInput = !!value; - } - }, - - // Methods - dispose: function SearchBox() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - AutoSuggestBox.AutoSuggestBox.prototype.dispose.call(this); - - if (this._focusOnKeyboardInput) { - Application._applicationListener.removeEventListener(this.element, "requestingfocusonkeyboardinput", this._requestingFocusOnKeyboardInputHandlerBind); - } - }, - - // Private methods - _disableControl: function SearchBox_disableControl() { - AutoSuggestBox.AutoSuggestBox.prototype._disableControl.call(this); - this._buttonElement.disabled = true; - this._buttonElement.classList.add(ClassName.searchBoxButtonDisabled); - this.element.classList.add(ClassName.searchBoxDisabled); - }, - - _enableControl: function SearchBox_enableControl() { - AutoSuggestBox.AutoSuggestBox.prototype._enableControl.call(this); - this._buttonElement.disabled = false; - this._buttonElement.classList.remove(ClassName.searchBoxButtonDisabled); - this.element.classList.remove(ClassName.searchBoxDisabled); - }, - - _renderSuggestion: function SearchBox_renderSuggestion(suggestion) { - // Overrides base class - var render = AutoSuggestBox.AutoSuggestBox.prototype._renderSuggestion.call(this, suggestion); - if (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Query) { - render.classList.add(ClassName.searchBoxSuggestionQuery); - } else if (suggestion.kind === _SuggestionManagerShim._SearchSuggestionKind.Separator) { - render.classList.add(ClassName.searchBoxSuggestionSeparator); - } else { - render.classList.add(ClassName.searchBoxSuggestionResult); - - var resultText = render.querySelector("." + AutoSuggestBox.ClassNames.asbSuggestionResultText); - resultText.classList.add(ClassName.searchBoxSuggestionResultText); - - var resultDetailText = render.querySelector("." + AutoSuggestBox.ClassNames.asbSuggestionResultDetailedText); - resultDetailText.classList.add(ClassName.searchBoxSuggestionResultDetailedText); - - var spans = render.querySelectorAll("." + AutoSuggestBox.ClassNames.asbHitHighlightSpan); - for (var i = 0, len = spans.length; i < len; i++) { - spans[i].classList.add(ClassName.searchBoxHitHighlightSpan); - } - var highlightTexts = render.querySelectorAll("." + AutoSuggestBox.ClassNames.asbBoxFlyoutHighlightText); - for (var i = 0, len = highlightTexts.length; i < len; i++) { - highlightTexts[i].classList.add(ClassName.searchBoxFlyoutHighlightText); - } - } - return render; - }, - - _selectSuggestionAtIndex: function SearchBox_selectSuggestionAtIndex(indexToSelect) { - // Overrides base class - AutoSuggestBox.AutoSuggestBox.prototype._selectSuggestionAtIndex.call(this, indexToSelect); - - var currentSelected = this.element.querySelector("." + ClassName.searchBoxSuggestionSelected); - currentSelected && currentSelected.classList.remove(ClassName.searchBoxSuggestionSelected); - var newSelected = this.element.querySelector("." + AutoSuggestBox.ClassNames.asbSuggestionSelected); - newSelected && newSelected.classList.add(ClassName.searchBoxSuggestionSelected); - }, - - _shouldIgnoreInput: function SearchBox_shouldIgnoreInput() { - // Overrides base class - var shouldIgnore = AutoSuggestBox.AutoSuggestBox.prototype._shouldIgnoreInput(); - var isButtonDown = _ElementUtilities._matchesSelector(this._buttonElement, ":active"); - - return shouldIgnore || isButtonDown; - }, - - _updateInputElementAriaLabel: function SearchBox_updateInputElementAriaLabel() { - // Override base class - this._inputElement.setAttribute("aria-label", - this._inputElement.placeholder ? _Resources._formatString(strings.ariaLabelInputPlaceHolder, this._inputElement.placeholder) : strings.ariaLabelInputNoPlaceHolder - ); - }, - - // Event Handlers - _buttonPointerDownHandler: function SearchBox_buttonPointerDownHandler(e) { - this._inputElement.focus(); - e.preventDefault(); - }, - - _buttonClickHandler: function SearchBox_buttonClickHandler(event) { - this._inputElement.focus(); - this._submitQuery(this._inputElement.value, true /*fillLinguisticDetails*/, event); - this._hideFlyout(); - }, - - _searchboxInputBlurHandler: function SearchBox_inputBlurHandler() { - _ElementUtilities.removeClass(this.element, ClassName.searchBoxInputFocus); - _ElementUtilities.removeClass(this._buttonElement, ClassName.searchBoxButtonInputFocus); - }, - - _searchboxInputFocusHandler: function SearchBox_inputFocusHandler() { - _ElementUtilities.addClass(this.element, ClassName.searchBoxInputFocus); - _ElementUtilities.addClass(this._buttonElement, ClassName.searchBoxButtonInputFocus); - }, - - // Type to search helpers - _requestingFocusOnKeyboardInputHandler: function SearchBox_requestingFocusOnKeyboardInputHandler() { - this._fireEvent(EventName.receivingfocusonkeyboardinput, null); - if (_Global.document.activeElement !== this._inputElement) { - try { - this._inputElement.focus(); - } catch (e) { - } - } - } - - }, { - createResultSuggestionImage: function SearchBox_createResultSuggestionImage(url) { - /// - /// - /// Creates the image argument for SearchSuggestionCollection.appendResultSuggestion. - /// - /// - /// The url of the image. - /// - /// - /// - if (_WinRT.Windows.Foundation.Uri && _WinRT.Windows.Storage.Streams.RandomAccessStreamReference) { - return _WinRT.Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(new _WinRT.Windows.Foundation.Uri(url)); - } - return url; - }, - - _getKeyModifiers: function SearchBox_getKeyModifiers(ev) { - // Returns the same value as https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.system.virtualkeymodifiers - var VirtualKeys = { - ctrlKey: 1, - altKey: 2, - shiftKey: 4 - }; - - var keyModifiers = 0; - if (ev.ctrlKey) { - keyModifiers |= VirtualKeys.ctrlKey; - } - if (ev.altKey) { - keyModifiers |= VirtualKeys.altKey; - } - if (ev.shiftKey) { - keyModifiers |= VirtualKeys.shiftKey; - } - return keyModifiers; - }, - - _isTypeToSearchKey: function searchBox__isTypeToSearchKey(event) { - if (event.shiftKey || event.ctrlKey || event.altKey) { - return false; - } - return true; - } - }); - _Base.Class.mix(SearchBox, _Control.DOMEventMixin); - return SearchBox; - }) - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// appbar,Flyout,Flyouts,registeredforsettings,SettingsFlyout,Statics,Syriac -define('WinJS/Controls/SettingsFlyout',[ - '../Core/_Global', - '../Core/_WinRT', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Events', - '../Core/_Resources', - '../Core/_WriteProfilerMark', - '../Animations', - '../Pages', - '../Promise', - '../_LightDismissService', - '../Utilities/_Dispose', - '../Utilities/_ElementUtilities', - '../Utilities/_ElementListUtilities', - '../Utilities/_Hoverable', - './_LegacyAppBar/_Constants', - './Flyout/_Overlay' - ], function settingsFlyoutInit(_Global, _WinRT, _Base, _BaseUtils, _ErrorFromName, _Events, _Resources, _WriteProfilerMark, Animations, Pages, Promise, _LightDismissService, _Dispose, _ElementUtilities, _ElementListUtilities, _Hoverable, _Constants, _Overlay) { - "use strict"; - - _Base.Namespace.define("WinJS.UI", { - /// - /// Provides users with fast, in-context access to settings that affect the current app. - /// - /// - /// Settings Flyout - /// - /// - /// - ///
- /// - ///
Custom Settings
- ///
- ///
- /// {Your Content Here} - ///
- /// ]]>
- /// Raised just before showing a SettingsFlyout. - /// Raised immediately after a SettingsFlyout is fully shown. - /// Raised just before hiding a SettingsFlyout. - /// Raised immediately after a SettingsFlyout is fully hidden. - /// The SettingsFlyout control itself. - /// - /// - SettingsFlyout: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - var createEvent = _Events._createEventProperty; - - var settingsPageIsFocusedOnce; - - // Constants for width - var settingsNarrow = "narrow", - settingsWide = "wide"; - - // Determine if the settings pane (system language) is RTL or not. - function _shouldAnimateFromLeft() { - if (_WinRT.Windows.UI.ApplicationSettings.SettingsEdgeLocation) { - var appSettings = _WinRT.Windows.UI.ApplicationSettings; - return (appSettings.SettingsPane.edge === appSettings.SettingsEdgeLocation.left); - } else { - return false; - } - } - - // Get the settings control by matching the settingsCommandId - // if no match we'll try to match element id - function _getChildSettingsControl(parentElement, id) { - var settingElements = parentElement.querySelectorAll("." + _Constants.settingsFlyoutClass); - var retValue, - control; - for (var i = 0; i < settingElements.length; i++) { - control = settingElements[i].winControl; - if (control) { - if (control.settingsCommandId === id) { - retValue = control; - break; - } - if (settingElements[i].id === id) { - retValue = retValue || control; - } - } - } - - return retValue; - } - - var SettingsFlyout = _Base.Class.derive(_Overlay._Overlay, function SettingsFlyout_ctor(element, options) { - /// - /// Creates a new SettingsFlyout control. - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the new SettingsFlyout. - /// - /// The new SettingsFlyout control. - /// - /// SettingsFlyout is deprecated and may not be available in future releases. Instead, put - /// settings on their own page within the app. - /// - /// - /// - - _ElementUtilities._deprecated(strings.settingsFlyoutIsDeprecated); - - // Make sure there's an input element - this._element = element || _Global.document.createElement("div"); - this._id = this._element.id || _ElementUtilities._uniqueID(this._element); - this._writeProfilerMark("constructor,StartTM"); - - // Call the base overlay constructor helper - this._baseOverlayConstructor(this._element, options); - - this._addFirstDiv(); - this._addFinalDiv(); - - // Handle "esc" & "tab" key presses - this._element.addEventListener("keydown", this._handleKeyDown, true); - - // Start settings hidden - this._element.style.visibilty = "hidden"; - this._element.style.display = "none"; - - // Attach our css class - _ElementUtilities.addClass(this._element, _Constants.settingsFlyoutClass); - - var that = this; - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._element, - tabIndex: this._element.hasAttribute("tabIndex") ? this._element.tabIndex : -1, - onLightDismiss: function () { - that.hide(); - }, - onTakeFocus: function (useSetActive) { - if (!that._dismissable.restoreFocus()) { - var firstDiv = that.element.querySelector("." + _Constants.firstDivClass); - if (firstDiv) { - if (!firstDiv.msSettingsFlyoutFocusOut) { - _ElementUtilities._addEventListener(firstDiv, "focusout", function () { settingsPageIsFocusedOnce = 1; }, false); - firstDiv.msSettingsFlyoutFocusOut = true; - } - - settingsPageIsFocusedOnce = 0; - _ElementUtilities._tryFocus(firstDiv, useSetActive); - } - } - }, - }); - - // apply the light theme styling to the win-content elements inside the SettingsFlyout - _ElementListUtilities.query("div.win-content", this._element). - forEach(function (e) { - if (!_ElementUtilities._matchesSelector(e, '.win-ui-dark, .win-ui-dark *')){ - _ElementUtilities.addClass(e, _Constants.flyoutLightClass); - } - }); - - // Make sure we have an ARIA role - var role = this._element.getAttribute("role"); - if (role === null || role === "" || role === undefined) { - this._element.setAttribute("role", "dialog"); - } - var label = this._element.getAttribute("aria-label"); - if (label === null || label === "" || label === undefined) { - this._element.setAttribute("aria-label", strings.ariaLabel); - } - - // Make sure animations are hooked up - this._currentAnimateIn = this._animateSlideIn; - this._currentAnimateOut = this._animateSlideOut; - this._writeProfilerMark("constructor,StopTM"); - }, { - // Public Properties - - /// - /// Width of the SettingsFlyout, "narrow", or "wide". - /// - /// SettingsFlyout.width may be altered or unavailable in future versions. Instead, style the CSS width property on elements with the .win-settingsflyout class. - /// - /// - /// - width: { - get: function () { - return this._width; - }, - - set: function (value) { - _ElementUtilities._deprecated(strings.widthDeprecationMessage); - if (value === this._width) { - return; - } - // Get rid of old class - if (this._width === settingsNarrow) { - _ElementUtilities.removeClass(this._element, _Constants.narrowClass); - } else if (this._width === settingsWide) { - _ElementUtilities.removeClass(this._element, _Constants.wideClass); - } - this._width = value; - - // Attach our new css class - if (this._width === settingsNarrow) { - _ElementUtilities.addClass(this._element, _Constants.narrowClass); - } else if (this._width === settingsWide) { - _ElementUtilities.addClass(this._element, _Constants.wideClass); - } - } - }, - - /// - /// Define the settings command Id for the SettingsFlyout control. - /// - /// - settingsCommandId: { - get: function () { - return this._settingsCommandId; - }, - - set: function (value) { - this._settingsCommandId = value; - } - }, - - /// Disable SettingsFlyout, setting or getting the HTML disabled attribute. When disabled the SettingsFlyout will no longer display with show(), and will hide if currently visible. - disabled: { - get: function () { - // Ensure it's a boolean because we're using the DOM element to keep in-sync - return !!this._element.disabled; - }, - set: function (value) { - // Force this check into a boolean because our current state could be a bit confused since we tie to the DOM element - value = !!value; - var oldValue = !!this._element.disabled; - if (oldValue !== value) { - this._element.disabled = value; - if (!this.hidden && this._element.disabled) { - this._dismiss(); - } - } - } - }, - - /// - /// Occurs immediately before the control is shown. - /// - onbeforeshow: createEvent(_Overlay._Overlay.beforeShow), - - /// - /// Occurs immediately after the control is shown. - /// - onaftershow: createEvent(_Overlay._Overlay.afterShow), - - /// - /// Occurs immediately before the control is hidden. - /// - onbeforehide: createEvent(_Overlay._Overlay.beforeHide), - - /// - /// Occurs immediately after the control is hidden. - /// - onafterhide: createEvent(_Overlay._Overlay.afterHide), - - show: function () { - /// - /// - /// Shows the SettingsFlyout, if hidden. - /// - /// - /// - // Just call private version to make appbar flags happy - - // Don't do anything if disabled - if (this.disabled) { - return; - } - this._writeProfilerMark("show,StartTM"); // The corresponding "stop" profiler mark is handled in _Overlay._baseEndShow(). - this._show(); - }, - - _dispose: function SettingsFlyout_dispose() { - _LightDismissService.hidden(this._dismissable); - _Dispose.disposeSubTree(this.element); - this._dismiss(); - }, - - _show: function SettingsFlyout_show() { - // We call our base "_baseShow" because SettingsFlyout overrides show - if (this._baseShow()) { - // Verify that the firstDiv and finalDiv are in the correct location. - // Move them to the correct location or add them if they are not. - if (!_ElementUtilities.hasClass(this.element.children[0], _Constants.firstDivClass)) { - var firstDiv = this.element.querySelectorAll("." + _Constants.firstDivClass); - if (firstDiv && firstDiv.length > 0) { - firstDiv.item(0).parentNode.removeChild(firstDiv.item(0)); - } - - this._addFirstDiv(); - } - - if (!_ElementUtilities.hasClass(this.element.children[this.element.children.length - 1], _Constants.finalDivClass)) { - var finalDiv = this.element.querySelectorAll("." + _Constants.finalDivClass); - if (finalDiv && finalDiv.length > 0) { - finalDiv.item(0).parentNode.removeChild(finalDiv.item(0)); - } - - this._addFinalDiv(); - } - - this._setBackButtonsAriaLabel(); - - _LightDismissService.shown(this._dismissable); - } - }, - - _setBackButtonsAriaLabel: function SettingsFlyout_setBackButtonsAriaLabel() { - var backbuttons = this.element.querySelectorAll(".win-backbutton"); - var label; - for (var i = 0; i < backbuttons.length; i++) { - label = backbuttons[i].getAttribute("aria-label"); - if (label === null || label === "" || label === undefined) { - backbuttons[i].setAttribute("aria-label", strings.backbuttonAriaLabel); - } - } - }, - - hide: function () { - /// - /// - /// Hides the SettingsFlyout, if visible, regardless of other state. - /// - /// - /// - // Just call private version to make appbar flags happy - this._writeProfilerMark("hide,StartTM"); // The corresponding "stop" profiler mark is handled in _Overlay._baseEndHide(). - this._hide(); - }, - - _hide: function SettingsFlyout_hide() { - this._baseHide(); - }, - - _beforeEndHide: function SettingsFlyout_beforeEndHide() { - _LightDismissService.hidden(this._dismissable); - }, - - // SettingsFlyout animations - _animateSlideIn: function SettingsFlyout_animateSlideIn() { - var animateFromLeft = _shouldAnimateFromLeft(); - var offset = animateFromLeft ? "-100px" : "100px"; - _ElementListUtilities.query("div.win-content", this._element). - forEach(function (e) { Animations.enterPage(e, { left: offset }); }); - - var where, - width = this._element.offsetWidth; - // Slide in from right side or left side? - if (animateFromLeft) { - // RTL - where = { top: "0px", left: "-" + width + "px" }; - this._element.style.right = "auto"; - this._element.style.left = "0px"; - } else { - // From right side - where = { top: "0px", left: width + "px" }; - this._element.style.right = "0px"; - this._element.style.left = "auto"; - } - - this._element.style.opacity = 1; - this._element.style.visibility = "visible"; - - return Animations.showPanel(this._element, where); - }, - - _animateSlideOut: function SettingsFlyout_animateSlideOut() { - var where, - width = this._element.offsetWidth; - if (_shouldAnimateFromLeft()) { - // RTL - where = { top: "0px", left: width + "px" }; - this._element.style.right = "auto"; - this._element.style.left = "-" + width + "px"; - } else { - // From right side - where = { top: "0px", left: "-" + width + "px" }; - this._element.style.right = "-" + width + "px"; - this._element.style.left = "auto"; - } - - return Animations.showPanel(this._element, where); - }, - - _fragmentDiv: { - get: function SettingsFlyout_fragmentDiv_get() { - return this._fragDiv; - }, - - set: function SettingsFlyout_fragmentDiv_set(value) { - this._fragDiv = value; - } - }, - - _unloadPage: function SettingsFlyout_unloadPage(event) { - var settingsControl = event.currentTarget.winControl; - settingsControl.removeEventListener(_Overlay._Overlay.afterHide, this._unloadPage, false); - - Promise.as().then(function () { - if (settingsControl._fragmentDiv) { - _Global.document.body.removeChild(settingsControl._fragmentDiv); - settingsControl._fragmentDiv = null; - } - }); - }, - - _dismiss: function SettingsFlyout_dismiss() { - this.addEventListener(_Overlay._Overlay.afterHide, this._unloadPage, false); - this._hide(); - }, - - _handleKeyDown: function SettingsFlyout_handleKeyDown(event) { - if ((event.keyCode === Key.space || event.keyCode === Key.enter) - && (this.children[0] === _Global.document.activeElement)) { - event.preventDefault(); - event.stopPropagation(); - this.winControl._dismiss(); - } else if (event.shiftKey && event.keyCode === Key.tab - && this.children[0] === _Global.document.activeElement) { - event.preventDefault(); - event.stopPropagation(); - var _elms = this.getElementsByTagName("*"); - - for (var i = _elms.length - 2; i >= 0; i--) { - _elms[i].focus(); - - if (_elms[i] === _Global.document.activeElement) { - break; - } - } - } - }, - - _focusOnLastFocusableElementFromParent: function SettingsFlyout_focusOnLastFocusableElementFromParent() { - var active = _Global.document.activeElement; - if (!settingsPageIsFocusedOnce || !active || !_ElementUtilities.hasClass(active, _Constants.firstDivClass)) { - return; - } - - var _elms = this.parentElement.getElementsByTagName("*"); - - // There should be at least 1 element in addition to the firstDiv & finalDiv - if (_elms.length <= 2) { - return; - } - - // Get the tabIndex set to the finalDiv (which is the highest) - var _highestTabIndex = _elms[_elms.length - 1].tabIndex; - - // If there are positive tabIndices, set focus to the element with the highest tabIndex. - // Otherwise set focus to the last focusable element in DOM order. - var i; - if (_highestTabIndex) { - for (i = _elms.length - 2; i > 0; i--) { - if (_elms[i].tabIndex === _highestTabIndex) { - _elms[i].focus(); - break; - } - } - } else { - for (i = _elms.length - 2; i > 0; i--) { - // Skip
with undefined tabIndex (To work around Win8 bug #622245) - if ((_elms[i].tagName !== "DIV") || (_elms[i].getAttribute("tabIndex") !== null)) { - _elms[i].focus(); - - if (_elms[i] === _Global.document.activeElement) { - break; - } - } - } - } - }, - - _focusOnFirstFocusableElementFromParent: function SettingsFlyout_focusOnFirstFocusableElementFromParent() { - var active = _Global.document.activeElement; - if (!active || !_ElementUtilities.hasClass(active, _Constants.finalDivClass)) { - return; - } - var _elms = this.parentElement.getElementsByTagName("*"); - - // There should be at least 1 element in addition to the firstDiv & finalDiv - if (_elms.length <= 2) { - return; - } - - // Get the tabIndex set to the firstDiv (which is the lowest) - var _lowestTabIndex = _elms[0].tabIndex; - - // If there are positive tabIndices, set focus to the element with the lowest tabIndex. - // Otherwise set focus to the first focusable element in DOM order. - var i; - if (_lowestTabIndex) { - for (i = 1; i < _elms.length - 1; i++) { - if (_elms[i].tabIndex === _lowestTabIndex) { - _elms[i].focus(); - break; - } - } - } else { - for (i = 1; i < _elms.length - 1; i++) { - // Skip
with undefined tabIndex (To work around Win8 bug #622245) - if ((_elms[i].tagName !== "DIV") || (_elms[i].getAttribute("tabIndex") !== null)) { - _elms[i].focus(); - - if (_elms[i] === _Global.document.activeElement) { - break; - } - } - } - } - }, - - // Create and add a new first div to the beginning of the list - _addFirstDiv: function SettingsFlyout_addFirstDiv() { - var _elms = this._element.getElementsByTagName("*"); - var _minTab = 0; - for (var i = 0; i < _elms.length; i++) { - if ((0 < _elms[i].tabIndex) && (_minTab === 0 || _elms[i].tabIndex < _minTab)) { - _minTab = _elms[i].tabIndex; - } - } - var firstDiv = _Global.document.createElement("div"); - firstDiv.className = _Constants.firstDivClass; - firstDiv.style.display = "inline"; - firstDiv.setAttribute("role", "menuitem"); - firstDiv.setAttribute("aria-hidden", "true"); - firstDiv.tabIndex = _minTab; - _ElementUtilities._addEventListener(firstDiv, "focusin", this._focusOnLastFocusableElementFromParent, false); - - // add to beginning - if (this._element.children[0]) { - this._element.insertBefore(firstDiv, this._element.children[0]); - } else { - this._element.appendChild(firstDiv); - } - }, - - // Create and add a new final div to the end of the list - _addFinalDiv: function SettingsFlyout_addFinalDiv() { - var _elms = this._element.getElementsByTagName("*"); - var _maxTab = 0; - for (var i = 0; i < _elms.length; i++) { - if (_elms[i].tabIndex > _maxTab) { - _maxTab = _elms[i].tabIndex; - } - } - var finalDiv = _Global.document.createElement("div"); - finalDiv.className = _Constants.finalDivClass; - finalDiv.style.display = "inline"; - finalDiv.setAttribute("role", "menuitem"); - finalDiv.setAttribute("aria-hidden", "true"); - finalDiv.tabIndex = _maxTab; - _ElementUtilities._addEventListener(finalDiv, "focusin", this._focusOnFirstFocusableElementFromParent, false); - - this._element.appendChild(finalDiv); - }, - - _writeProfilerMark: function SettingsFlyout_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI.SettingsFlyout:" + this._id + ":" + text); - } - }); - - // Statics - SettingsFlyout.show = function () { - /// - /// - /// Shows the SettingsPane UI, if hidden, regardless of other states. - /// - /// - /// - /// Show the main settings pane - if (_WinRT.Windows.UI.ApplicationSettings.SettingsPane) { - _WinRT.Windows.UI.ApplicationSettings.SettingsPane.show(); - } - // And hide the WWA one - var elements = _Global.document.querySelectorAll('div[data-win-control="WinJS.UI.SettingsFlyout"]'); - var len = elements.length; - for (var i = 0; i < len; i++) { - var settingsFlyout = elements[i].winControl; - if (settingsFlyout) { - settingsFlyout._dismiss(); - } - } - }; - - var _settingsEvent = { event: undefined }; - SettingsFlyout.populateSettings = function (e) { - /// - /// - /// Loads a portion of the SettingsFlyout. Your app calls this when the user invokes a settings command and the WinJS.Application.onsettings event occurs. - /// - /// - /// An object that contains information about the event, received from the WinJS.Application.onsettings event. The detail property of this object contains - /// the applicationcommands sub-property that you set to an array of settings commands. - /// - /// - /// - _settingsEvent.event = e.detail; - - if (_settingsEvent.event.applicationcommands) { - var n = _WinRT.Windows.UI.ApplicationSettings; - Object.keys(_settingsEvent.event.applicationcommands).forEach(function (name) { - var setting = _settingsEvent.event.applicationcommands[name]; - if (!setting.title) { setting.title = name; } - var command = new n.SettingsCommand(name, setting.title, SettingsFlyout._onSettingsCommand); - _settingsEvent.event.e.request.applicationCommands.append(command); - }); - } - }; - - SettingsFlyout._onSettingsCommand = function (command) { - var id = command.id; - if (_settingsEvent.event.applicationcommands && _settingsEvent.event.applicationcommands[id]) { - SettingsFlyout.showSettings(id, _settingsEvent.event.applicationcommands[id].href); - } - }; - - SettingsFlyout.showSettings = function (id, path) { - /// - /// - /// Show the SettingsFlyout using the settings element identifier (ID) and the path of the page that contains the settings element. - /// - /// - /// The ID of the settings element. - /// - /// - /// The path of the page that contains the settings element. - /// - /// - /// - var control = _getChildSettingsControl(_Global.document, id); - if (control) { - control.show(); - } else if (path) { - var divElement = _Global.document.createElement("div"); - divElement = _Global.document.body.appendChild(divElement); - Pages.render(path, divElement).then(function () { - control = _getChildSettingsControl(divElement, id); - if (control) { - control._fragmentDiv = divElement; - control.show(); - } else { - _Global.document.body.removeChild(divElement); - } - }); - } else { - throw new _ErrorFromName("WinJS.UI.SettingsFlyout.BadReference", strings.badReference); - } - }; - - var strings = { - get ariaLabel() { return _Resources._getWinJSString("ui/settingsFlyoutAriaLabel").value; }, - get badReference() { return "Invalid argument: Invalid href to settings flyout fragment"; }, - get backbuttonAriaLabel() { return _Resources._getWinJSString("ui/backbuttonarialabel").value; }, - get widthDeprecationMessage() { return "SettingsFlyout.width may be altered or unavailable in future versions. Instead, style the CSS width property on elements with the .win-settingsflyout class."; }, - get settingsFlyoutIsDeprecated() { return "SettingsFlyout is deprecated and may not be available in future releases. Instead, put settings on their own page within the app."; } - }; - - return SettingsFlyout; - }) - }); - - -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/NavBar/_Command',[ - 'exports', - '../../Core/_Global', - '../../Core/_Base', - '../../Core/_ErrorFromName', - '../../Core/_Resources', - '../../ControlProcessor', - '../../Navigation', - '../../Utilities/_Control', - '../../Utilities/_ElementUtilities', - '../AppBar/_Icon' - ], function NavBarCommandInit(exports, _Global, _Base, _ErrorFromName, _Resources, ControlProcessor, Navigation, _Control, _ElementUtilities, _Icon) { - "use strict"; - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - _WinPressed: _Base.Namespace._lazy(function () { - var WinPressed = _Base.Class.define(function _WinPressed_ctor(element) { - // WinPressed is the combination of :hover:active - // :hover is delayed by trident for touch by 300ms so if you want :hover:active to work quickly you need to - // use this behavior. - // :active does not bubble to its parent like :hover does so this is also useful for that scenario. - this._element = element; - _ElementUtilities._addEventListener(this._element, "pointerdown", this._MSPointerDownButtonHandler.bind(this)); - }, { - _MSPointerDownButtonHandler: function _WinPressed_MSPointerDownButtonHandler(ev) { - if (!this._pointerUpBound) { - this._pointerUpBound = this._MSPointerUpHandler.bind(this); - this._pointerCancelBound = this._MSPointerCancelHandler.bind(this); - this._pointerOverBound = this._MSPointerOverHandler.bind(this); - this._pointerOutBound = this._MSPointerOutHandler.bind(this); - } - - if (ev.isPrimary) { - if (this._pointerId) { - this._resetPointer(); - } - - if (!_ElementUtilities._matchesSelector(ev.target, ".win-interactive, .win-interactive *")) { - this._pointerId = ev.pointerId; - - _ElementUtilities._addEventListener(_Global, "pointerup", this._pointerUpBound, true); - _ElementUtilities._addEventListener(_Global, "pointercancel", this._pointerCancelBound), true; - _ElementUtilities._addEventListener(this._element, "pointerover", this._pointerOverBound, true); - _ElementUtilities._addEventListener(this._element, "pointerout", this._pointerOutBound, true); - - _ElementUtilities.addClass(this._element, WinPressed.winPressed); - } - } - }, - - _MSPointerOverHandler: function _WinPressed_MSPointerOverHandler(ev) { - if (this._pointerId === ev.pointerId) { - _ElementUtilities.addClass(this._element, WinPressed.winPressed); - } - }, - - _MSPointerOutHandler: function _WinPressed_MSPointerOutHandler(ev) { - if (this._pointerId === ev.pointerId) { - _ElementUtilities.removeClass(this._element, WinPressed.winPressed); - } - }, - - _MSPointerCancelHandler: function _WinPressed_MSPointerCancelHandler(ev) { - if (this._pointerId === ev.pointerId) { - this._resetPointer(); - } - }, - - _MSPointerUpHandler: function _WinPressed_MSPointerUpHandler(ev) { - if (this._pointerId === ev.pointerId) { - this._resetPointer(); - } - }, - - _resetPointer: function _WinPressed_resetPointer() { - this._pointerId = null; - - _ElementUtilities._removeEventListener(_Global, "pointerup", this._pointerUpBound, true); - _ElementUtilities._removeEventListener(_Global, "pointercancel", this._pointerCancelBound, true); - _ElementUtilities._removeEventListener(this._element, "pointerover", this._pointerOverBound, true); - _ElementUtilities._removeEventListener(this._element, "pointerout", this._pointerOutBound, true); - - _ElementUtilities.removeClass(this._element, WinPressed.winPressed); - }, - - dispose: function _WinPressed_dispose() { - if (this._disposed) { - return; - } - this._disposed = true; - - this._resetPointer(); - } - }, { - winPressed: "win-pressed" - }); - - return WinPressed; - }), - /// - /// - /// Represents a navigation command in an NavBarContainer. - /// - /// - /// - /// - /// - ///
]]> - /// Styles the entire NavBarCommand control. - /// Styles the main button in a NavBarCommand. - /// Styles the split button in a NavBarCommand - /// Styles the icon in the main button of a NavBarCommand. - /// Styles the label in the main button of a NavBarCommand. - /// - /// - NavBarCommand: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - var strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; } - }; - - var NavBarCommand = _Base.Class.define(function NavBarCommand_ctor(element, options) { - /// - /// - /// Creates a new NavBarCommand. - /// - /// - /// The DOM element that will host the new NavBarCommand control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". - /// - /// - /// The new NavBarCommand. - /// - /// - /// - element = element || _Global.document.createElement("DIV"); - options = options || {}; - - if (element.winControl) { - throw new _ErrorFromName("WinJS.UI.NavBarCommand.DuplicateConstruction", strings.duplicateConstruction); - } - - // Attaching JS control to DOM element - element.winControl = this; - this._element = element; - _ElementUtilities.addClass(this.element, NavBarCommand._ClassName.navbarcommand); - _ElementUtilities.addClass(this.element, "win-disposable"); - - this._tooltip = null; - this._splitOpened = false; - this._buildDom(); - element.addEventListener('keydown', this._keydownHandler.bind(this)); - - _Control.setOptions(this, options); - }, { - /// - element: { - get: function () { - return this._element; - } - }, - - /// - /// Gets or sets the label of the NavBarCommand. - /// - /// - label: { - get: function () { - return this._label; - }, - set: function (value) { - this._label = value; - this._labelEl.textContent = value; - } - }, - - /// - /// Gets or sets the tooltip of the NavBarCommand. - /// - /// - tooltip: { - get: function () { - return this._tooltip; - }, - set: function (value) { - this._tooltip = value; - if (this._tooltip || this._tooltip === "") { - this._element.setAttribute('title', this._tooltip); - } else { - this._element.removeAttribute('title'); - } - } - }, - - /// - /// Gets or sets the icon of the NavBarCommand. This value is either one of the values of the AppBarIcon enumeration or the path of a custom PNG file. - /// - /// - icon: { - get: function () { - return this._icon; - }, - set: function (value) { - this._icon = (_Icon[value] || value); - - // If the icon's a single character, presume a glyph - if (this._icon && this._icon.length === 1) { - // Set the glyph - this._imageSpan.textContent = this._icon; - this._imageSpan.style.backgroundImage = ""; - this._imageSpan.style.msHighContrastAdjust = ""; - this._imageSpan.style.display = ""; - } else if (this._icon && this._icon.length > 1) { - // Must be an image, set that - this._imageSpan.textContent = ""; - this._imageSpan.style.backgroundImage = this._icon; - this._imageSpan.style.msHighContrastAdjust = "none"; - this._imageSpan.style.display = ""; - } else { - this._imageSpan.textContent = ""; - this._imageSpan.style.backgroundImage = ""; - this._imageSpan.style.msHighContrastAdjust = ""; - this._imageSpan.style.display = "none"; - } - } - }, - - /// - /// Gets or sets the command's target location. - /// - /// - location: { - get: function () { - return this._location; - }, - set: function (value) { - this._location = value; - } - }, - - /// - /// Gets or sets the state value used for navigation. The command passes this object to the WinJS.Navigation.navigate function. - /// - /// - state: { - get: function () { - return this._state; - }, - set: function (value) { - this._state = value; - } - }, - - /// - /// Gets or sets a value that specifies whether the NavBarCommand has a split button. - /// - /// - splitButton: { - get: function () { - return this._split; - }, - set: function (value) { - this._split = value; - if (this._split) { - this._splitButtonEl.style.display = ""; - } else { - this._splitButtonEl.style.display = "none"; - } - } - }, - - /// - splitOpened: { - get: function () { - return this._splitOpened; - }, - set: function (value) { - if (this._splitOpened !== !!value) { - this._toggleSplit(); - } - } - }, - - _toggleSplit: function NavBarCommand_toggleSplit() { - this._splitOpened = !this._splitOpened; - if (this._splitOpened) { - _ElementUtilities.addClass(this._splitButtonEl, NavBarCommand._ClassName.navbarcommandsplitbuttonopened); - this._splitButtonEl.setAttribute("aria-expanded", "true"); - } else { - _ElementUtilities.removeClass(this._splitButtonEl, NavBarCommand._ClassName.navbarcommandsplitbuttonopened); - this._splitButtonEl.setAttribute("aria-expanded", "false"); - } - this._fireEvent(NavBarCommand._EventName._splitToggle); - }, - - _rtl: { - get: function () { - return _Global.getComputedStyle(this.element).direction === "rtl"; - } - }, - - _keydownHandler: function NavBarCommand_keydownHandler(ev) { - if (_ElementUtilities._matchesSelector(ev.target, ".win-interactive, .win-interactive *")) { - return; - } - - var leftStr = this._rtl ? Key.rightArrow : Key.leftArrow; - var rightStr = this._rtl ? Key.leftArrow : Key.rightArrow; - - if (!ev.altKey && (ev.keyCode === leftStr || ev.keyCode === Key.home || ev.keyCode === Key.end) && ev.target === this._splitButtonEl) { - _ElementUtilities._setActive(this._buttonEl); - if (ev.keyCode === leftStr) { - ev.stopPropagation(); - } - ev.preventDefault(); - } else if (!ev.altKey && ev.keyCode === rightStr && this.splitButton && (ev.target === this._buttonEl || this._buttonEl.contains(ev.target))) { - _ElementUtilities._setActive(this._splitButtonEl); - if (ev.keyCode === rightStr) { - ev.stopPropagation(); - } - ev.preventDefault(); - } else if ((ev.keyCode === Key.space || ev.keyCode === Key.enter) && (ev.target === this._buttonEl || this._buttonEl.contains(ev.target))) { - if (this.location) { - Navigation.navigate(this.location, this.state); - } - this._fireEvent(NavBarCommand._EventName._invoked); - } else if ((ev.keyCode === Key.space || ev.keyCode === Key.enter) && ev.target === this._splitButtonEl) { - this._toggleSplit(); - } - }, - - _getFocusInto: function NavBarCommand_getFocusInto(keyCode) { - var leftStr = this._rtl ? Key.rightArrow : Key.leftArrow; - if ((keyCode === leftStr) && this.splitButton) { - return this._splitButtonEl; - } else { - return this._buttonEl; - } - }, - - _buildDom: function NavBarCommand_buildDom() { - var markup = - '' + - ''; - this.element.insertAdjacentHTML("afterBegin", markup); - - this._buttonEl = this.element.firstElementChild; - this._buttonPressedBehavior = new exports._WinPressed(this._buttonEl); - this._contentEl = this._buttonEl.firstElementChild; - this._imageSpan = this._contentEl.firstElementChild; - this._imageSpan.style.display = "none"; - this._labelEl = this._imageSpan.nextElementSibling; - this._splitButtonEl = this._buttonEl.nextElementSibling; - this._splitButtonPressedBehavior = new exports._WinPressed(this._splitButtonEl); - this._splitButtonEl.style.display = "none"; - - _ElementUtilities._ensureId(this._buttonEl); - this._splitButtonEl.setAttribute("aria-labelledby", this._buttonEl.id); - - this._buttonEl.addEventListener("click", this._handleButtonClick.bind(this)); - - var mutationObserver = new _ElementUtilities._MutationObserver(this._splitButtonAriaExpandedPropertyChangeHandler.bind(this)); - mutationObserver.observe(this._splitButtonEl, { attributes: true, attributeFilter: ["aria-expanded"] }); - this._splitButtonEl.addEventListener("click", this._handleSplitButtonClick.bind(this)); - - // reparent any other elements. - var tempEl = this._splitButtonEl.nextSibling; - while (tempEl) { - this._buttonEl.insertBefore(tempEl, this._contentEl); - if (tempEl.nodeName !== "#text") { - ControlProcessor.processAll(tempEl); - } - tempEl = this._splitButtonEl.nextSibling; - } - }, - - _handleButtonClick: function NavBarCommand_handleButtonClick(ev) { - var srcElement = ev.target; - if (!_ElementUtilities._matchesSelector(srcElement, ".win-interactive, .win-interactive *")) { - if (this.location) { - Navigation.navigate(this.location, this.state); - } - this._fireEvent(NavBarCommand._EventName._invoked); - } - }, - - _splitButtonAriaExpandedPropertyChangeHandler: function NavBarCommand_splitButtonAriaExpandedPropertyChangeHandler() { - if ((this._splitButtonEl.getAttribute("aria-expanded") === "true") !== this._splitOpened) { - this._toggleSplit(); - } - }, - - _handleSplitButtonClick: function NavBarCommand_handleSplitButtonClick() { - this._toggleSplit(); - }, - - _fireEvent: function NavBarCommand_fireEvent(type, detail) { - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(type, true, false, detail); - this.element.dispatchEvent(event); - }, - - dispose: function NavBarCommand_dispose() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - - this._buttonPressedBehavior.dispose(); - this._splitButtonPressedBehavior.dispose(); - } - }, { - _ClassName: { - navbarcommand: "win-navbarcommand", - navbarcommandbutton: "win-navbarcommand-button", - navbarcommandbuttoncontent: "win-navbarcommand-button-content", - navbarcommandsplitbutton: "win-navbarcommand-splitbutton", - navbarcommandsplitbuttonopened: "win-navbarcommand-splitbutton-opened", - navbarcommandicon: "win-navbarcommand-icon", - navbarcommandlabel: "win-navbarcommand-label" - }, - _EventName: { - _invoked: "_invoked", - _splitToggle: "_splittoggle" - } - }); - _Base.Class.mix(NavBarCommand, _Control.DOMEventMixin); - return NavBarCommand; - }) - }); - -}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/NavBar/_Container',[ - 'exports', - '../../Core/_Global', - '../../Core/_Base', - '../../Core/_BaseUtils', - '../../Core/_ErrorFromName', - '../../Core/_Events', - '../../Core/_Log', - '../../Core/_Resources', - '../../Core/_WriteProfilerMark', - '../../Animations', - '../../Animations/_TransitionAnimation', - '../../BindingList', - '../../ControlProcessor', - '../../Navigation', - '../../Promise', - '../../Scheduler', - '../../Utilities/_Control', - '../../Utilities/_ElementUtilities', - '../../Utilities/_KeyboardBehavior', - '../../Utilities/_UI', - '../_LegacyAppBar/_Constants', - '../Repeater', - './_Command' -], function NavBarContainerInit(exports, _Global, _Base, _BaseUtils, _ErrorFromName, _Events, _Log, _Resources, _WriteProfilerMark, Animations, _TransitionAnimation, BindingList, ControlProcessor, Navigation, Promise, Scheduler, _Control, _ElementUtilities, _KeyboardBehavior, _UI, _Constants, Repeater, _Command) { - "use strict"; - - function nobodyHasFocus() { - return _Global.document.activeElement === null || _Global.document.activeElement === _Global.document.body; - } - - _Base.Namespace._moduleDefine(exports, "WinJS.UI", { - /// - /// - /// Contains a group of NavBarCommand objects in a NavBar. - /// - /// - /// - /// - /// - /// - ///
- ///
]]> - /// Raised when a NavBarCommand is invoked. - /// Raised when the split button on a NavBarCommand is toggled. - /// Styles the entire NavBarContainer control. - /// - /// Styles the page indication for the NavBarContainer. - /// - /// Styles the page indication for each page. - /// - /// Styles the indication of the current page. - /// - /// Styles the area that contains items for the NavBarContainer. - /// Styles left and right navigation arrows. - /// Styles the left navigation arrow. - /// Styles the right navigation arrow. - /// - /// - NavBarContainer: _Base.Namespace._lazy(function () { - var Key = _ElementUtilities.Key; - - var buttonFadeDelay = 3000; - var PT_TOUCH = _ElementUtilities._MSPointerEvent.MSPOINTER_TYPE_TOUCH || "touch"; - var MS_MANIPULATION_STATE_STOPPED = 0; - - var createEvent = _Events._createEventProperty; - var eventNames = { - invoked: "invoked", - splittoggle: "splittoggle" - }; - - var strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get navBarContainerViewportAriaLabel() { return _Resources._getWinJSString("ui/navBarContainerViewportAriaLabel").value; } - }; - - var NavBarContainer = _Base.Class.define(function NavBarContainer_ctor(element, options) { - /// - /// - /// Creates a new NavBarContainer. - /// - /// - /// The DOM element that will host the NavBarContainer control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". - /// - /// - /// The new NavBarContainer. - /// - /// - /// - - element = element || _Global.document.createElement("DIV"); - this._id = element.id || _ElementUtilities._uniqueID(element); - this._writeProfilerMark("constructor,StartTM"); - - options = options || {}; - - if (element.winControl) { - throw new _ErrorFromName("WinJS.UI.NavBarContainer.DuplicateConstruction", strings.duplicateConstruction); - } - - // Attaching JS control to DOM element - element.winControl = this; - this._element = element; - _ElementUtilities.addClass(this.element, NavBarContainer._ClassName.navbarcontainer); - _ElementUtilities.addClass(this.element, "win-disposable"); - if (!element.getAttribute("tabIndex")) { - element.tabIndex = -1; - } - - this._focusCurrentItemPassivelyBound = this._focusCurrentItemPassively.bind(this); - this._closeSplitAndResetBound = this._closeSplitAndReset.bind(this); - this._currentManipulationState = MS_MANIPULATION_STATE_STOPPED; - - this._panningDisabled = !_ElementUtilities._supportsSnapPoints; - this._fixedSize = false; - this._maxRows = 1; - this._sizes = {}; - - this._setupTree(); - - this._duringConstructor = true; - - this._dataChangingBound = this._dataChanging.bind(this); - this._dataChangedBound = this._dataChanged.bind(this); - - Navigation.addEventListener('navigated', this._closeSplitAndResetBound); - - // Don't use set options for the properties so we can control the ordering to avoid rendering multiple times. - this.layout = options.layout || _UI.Orientation.horizontal; - if (options.maxRows) { - this.maxRows = options.maxRows; - } - if (options.template) { - this.template = options.template; - } - if (options.data) { - this.data = options.data; - } - if (options.fixedSize) { - this.fixedSize = options.fixedSize; - } - - // Events only - _Control._setOptions(this, options, true); - - this._duringConstructor = false; - - if (options.currentIndex) { - this.currentIndex = options.currentIndex; - } - - this._updatePageUI(); - - Scheduler.schedule(function NavBarContainer_async_initialize() { - this._updateAppBarReference(); - }, Scheduler.Priority.normal, this, "WinJS.UI.NavBarContainer_async_initialize"); - - this._writeProfilerMark("constructor,StopTM"); - }, { - /// - element: { - get: function () { - return this._element; - } - }, - - /// - /// Gets or sets a Template or custom rendering function that defines the HTML of each item within the NavBarContainer. - /// - /// - template: { - get: function () { - return this._template; - }, - set: function (value) { - this._template = value; - if (this._repeater) { - var hadFocus = this.element.contains(_Global.document.activeElement); - - if (!this._duringConstructor) { - this._closeSplitIfOpen(); - } - - // the repeater's template is wired up to this._render() so just resetting it will rebuild the tree. - this._repeater.template = this._repeater.template; - - if (!this._duringConstructor) { - this._measured = false; - this._sizes.itemMeasured = false; - this._reset(); - if (hadFocus) { - this._keyboardBehavior._focus(0); - } - } - } - } - }, - - _render: function NavBarContainer_render(item) { - var navbarCommandEl = _Global.document.createElement('div'); - - var template = this._template; - if (template) { - if (template.render) { - template.render(item, navbarCommandEl); - } else if (template.winControl && template.winControl.render) { - template.winControl.render(item, navbarCommandEl); - } else { - navbarCommandEl.appendChild(template(item)); - } - } - - // Create the NavBarCommand after calling render so that the reparenting in navbarCommand works. - var navbarCommand = new _Command.NavBarCommand(navbarCommandEl, item); - return navbarCommand._element; - }, - - /// - /// Gets or sets the WinJS.Binding.List that provides the NavBarContainer with items to display. - /// - /// - data: { - get: function () { - return this._repeater && this._repeater.data; - }, - set: function (value) { - if (!value) { - value = new BindingList.List(); - } - - if (!this._duringConstructor) { - this._closeSplitIfOpen(); - } - - this._removeDataChangingEvents(); - this._removeDataChangedEvents(); - - var hadFocus = this.element.contains(_Global.document.activeElement); - - if (!this._repeater) { - this._surfaceEl.innerHTML = ""; - this._repeater = new Repeater.Repeater(this._surfaceEl, { - template: this._render.bind(this) - }); - } - - this._addDataChangingEvents(value); - this._repeater.data = value; - this._addDataChangedEvents(value); - - if (!this._duringConstructor) { - this._measured = false; - this._sizes.itemMeasured = false; - this._reset(); - if (hadFocus) { - this._keyboardBehavior._focus(0); - } - } - } - }, - - /// - /// Gets or sets the number of rows allowed to be used before items are placed on additional pages. - /// - /// - maxRows: { - get: function () { - return this._maxRows; - }, - set: function (value) { - value = (+value === value) ? value : 1; - this._maxRows = Math.max(1, value); - - if (!this._duringConstructor) { - this._closeSplitIfOpen(); - - this._measured = false; - this._reset(); - } - } - }, - - /// - /// Gets or sets a value that specifies whether the NavBarContainer has a horizontal or vertical layout. The default is "horizontal". - /// - /// - layout: { - get: function () { - return this._layout; - }, - set: function (value) { - if (value === _UI.Orientation.vertical) { - this._layout = _UI.Orientation.vertical; - _ElementUtilities.removeClass(this.element, NavBarContainer._ClassName.horizontal); - _ElementUtilities.addClass(this.element, NavBarContainer._ClassName.vertical); - } else { - this._layout = _UI.Orientation.horizontal; - _ElementUtilities.removeClass(this.element, NavBarContainer._ClassName.vertical); - _ElementUtilities.addClass(this.element, NavBarContainer._ClassName.horizontal); - } - - this._viewportEl.style.msScrollSnapType = ""; - this._zooming = false; - - if (!this._duringConstructor) { - this._measured = false; - this._sizes.itemMeasured = false; - this._ensureVisible(this._keyboardBehavior.currentIndex, true); - this._updatePageUI(); - this._closeSplitIfOpen(); - } - } - }, - - /// - currentIndex: { - get: function () { - return this._keyboardBehavior.currentIndex; - }, - set: function (value) { - if (value === +value) { - var hadFocus = this.element.contains(_Global.document.activeElement); - - this._keyboardBehavior.currentIndex = value; - - this._ensureVisible(this._keyboardBehavior.currentIndex, true); - - if (hadFocus) { - this._keyboardBehavior._focus(); - } - } - } - }, - - /// - /// Gets or sets a value that specifies whether child NavBarCommand objects should be a fixed width when there are multiple pages. A value of true indicates - /// that the NavBarCommand objects use a fixed width; a value of false indicates that they use a dynamic width. - /// - /// - fixedSize: { - get: function () { - return this._fixedSize; - }, - set: function (value) { - this._fixedSize = !!value; - - if (!this._duringConstructor) { - this._closeSplitIfOpen(); - - if (!this._measured) { - this._measure(); - } else if (this._surfaceEl.children.length > 0) { - this._updateGridStyles(); - } - } - } - }, - - /// - /// Raised when a NavBarCommand has been invoked. - /// - /// - oninvoked: createEvent(eventNames.invoked), - - /// - /// Raised when the split button on a NavBarCommand is toggled. - /// - /// - onsplittoggle: createEvent(eventNames.splittoggle), - - forceLayout: function NavBarContainer_forceLayout() { - /// - /// - /// Forces the NavBarContainer to update scroll positions and if the NavBar has changed size, it will also re-measure. - /// Use this function when making the NavBarContainer visible again after you set its style.display property to "none". - /// - /// - /// - this._resizeHandler(); - if (this._measured) { - this._scrollPosition = _ElementUtilities.getScrollPosition(this._viewportEl)[(this.layout === _UI.Orientation.horizontal ? "scrollLeft" : "scrollTop")]; - } - - this._duringForceLayout = true; - this._ensureVisible(this._keyboardBehavior.currentIndex, true); - this._updatePageUI(); - this._duringForceLayout = false; - }, - - _updateAppBarReference: function NavBarContainer_updateAppBarReference() { - if (!this._appBarEl || !this._appBarEl.contains(this.element)) { - if (this._appBarEl) { - this._appBarEl.removeEventListener('beforeopen', this._closeSplitAndResetBound); - this._appBarEl.removeEventListener('beforeopen', this._resizeImplBound); - this._appBarEl.removeEventListener('afteropen', this._focusCurrentItemPassivelyBound); - } - - var appBarEl = this.element.parentNode; - while (appBarEl && !_ElementUtilities.hasClass(appBarEl, _Constants.appBarClass)) { - appBarEl = appBarEl.parentNode; - } - this._appBarEl = appBarEl; - - if (this._appBarEl) { - this._appBarEl.addEventListener('beforeopen', this._closeSplitAndResetBound); - this._appBarEl.addEventListener('afteropen', this._focusCurrentItemPassivelyBound); - } - } - }, - - _closeSplitAndReset: function NavBarContainer_closeSplitAndReset() { - this._closeSplitIfOpen(); - this._reset(); - }, - - _dataChanging: function NavBarContainer_dataChanging(ev) { - // Store the element that was active so that we can detect - // if the focus went away because of the data change. - this._elementHadFocus = _Global.document.activeElement; - - if (this._currentSplitNavItem && this._currentSplitNavItem.splitOpened) { - if (ev.type === "itemremoved") { - if (this._surfaceEl.children[ev.detail.index].winControl === this._currentSplitNavItem) { - this._closeSplitIfOpen(); - } - } else if (ev.type === "itemchanged") { - if (this._surfaceEl.children[ev.detail.index].winControl === this._currentSplitNavItem) { - this._closeSplitIfOpen(); - } - } else if (ev.type === "itemmoved") { - if (this._surfaceEl.children[ev.detail.oldIndex].winControl === this._currentSplitNavItem) { - this._closeSplitIfOpen(); - } - } else if (ev.type === "reload") { - this._closeSplitIfOpen(); - } - } - }, - - _dataChanged: function NavBarContainer_dataChanged(ev) { - this._measured = false; - - if (ev.type === "itemremoved") { - if (ev.detail.index < this._keyboardBehavior.currentIndex) { - this._keyboardBehavior.currentIndex--; - } else if (ev.detail.index === this._keyboardBehavior.currentIndex) { - // This clamps if the item being removed was the last item in the list - this._keyboardBehavior.currentIndex = this._keyboardBehavior.currentIndex; - if (nobodyHasFocus() && this._elementHadFocus) { - this._keyboardBehavior._focus(); - } - } - } else if (ev.type === "itemchanged") { - if (ev.detail.index === this._keyboardBehavior.currentIndex) { - if (nobodyHasFocus() && this._elementHadFocus) { - this._keyboardBehavior._focus(); - } - } - } else if (ev.type === "iteminserted") { - if (ev.detail.index <= this._keyboardBehavior.currentIndex) { - this._keyboardBehavior.currentIndex++; - } - } else if (ev.type === "itemmoved") { - if (ev.detail.oldIndex === this._keyboardBehavior.currentIndex) { - this._keyboardBehavior.currentIndex = ev.detail.newIndex; - if (nobodyHasFocus() && this._elementHadFocus) { - this._keyboardBehavior._focus(); - } - } - } else if (ev.type === "reload") { - this._keyboardBehavior.currentIndex = 0; - if (nobodyHasFocus() && this._elementHadFocus) { - this._keyboardBehavior._focus(); - } - } - - this._ensureVisible(this._keyboardBehavior.currentIndex, true); - this._updatePageUI(); - }, - - _focusCurrentItemPassively: function NavBarContainer_focusCurrentItemPassively() { - if (this.element.contains(_Global.document.activeElement)) { - this._keyboardBehavior._focus(); - } - }, - - _reset: function NavBarContainer_reset() { - this._keyboardBehavior.currentIndex = 0; - - if (this.element.contains(_Global.document.activeElement)) { - this._keyboardBehavior._focus(0); - } - - this._viewportEl.style.msScrollSnapType = ""; - this._zooming = false; - - this._ensureVisible(0, true); - this._updatePageUI(); - }, - - _removeDataChangedEvents: function NavBarContainer_removeDataChangedEvents() { - if (this._repeater) { - this._repeater.data.removeEventListener("itemchanged", this._dataChangedBound); - this._repeater.data.removeEventListener("iteminserted", this._dataChangedBound); - this._repeater.data.removeEventListener("itemmoved", this._dataChangedBound); - this._repeater.data.removeEventListener("itemremoved", this._dataChangedBound); - this._repeater.data.removeEventListener("reload", this._dataChangedBound); - } - }, - - _addDataChangedEvents: function NavBarContainer_addDataChangedEvents() { - if (this._repeater) { - this._repeater.data.addEventListener("itemchanged", this._dataChangedBound); - this._repeater.data.addEventListener("iteminserted", this._dataChangedBound); - this._repeater.data.addEventListener("itemmoved", this._dataChangedBound); - this._repeater.data.addEventListener("itemremoved", this._dataChangedBound); - this._repeater.data.addEventListener("reload", this._dataChangedBound); - } - }, - - _removeDataChangingEvents: function NavBarContainer_removeDataChangingEvents() { - if (this._repeater) { - this._repeater.data.removeEventListener("itemchanged", this._dataChangingBound); - this._repeater.data.removeEventListener("iteminserted", this._dataChangingBound); - this._repeater.data.removeEventListener("itemmoved", this._dataChangingBound); - this._repeater.data.removeEventListener("itemremoved", this._dataChangingBound); - this._repeater.data.removeEventListener("reload", this._dataChangingBound); - } - }, - - _addDataChangingEvents: function NavBarContainer_addDataChangingEvents(bindingList) { - bindingList.addEventListener("itemchanged", this._dataChangingBound); - bindingList.addEventListener("iteminserted", this._dataChangingBound); - bindingList.addEventListener("itemmoved", this._dataChangingBound); - bindingList.addEventListener("itemremoved", this._dataChangingBound); - bindingList.addEventListener("reload", this._dataChangingBound); - }, - - _mouseleave: function NavBarContainer_mouseleave() { - if (this._mouseInViewport) { - this._mouseInViewport = false; - this._updateArrows(); - } - }, - - _MSPointerDown: function NavBarContainer_MSPointerDown(ev) { - if (ev.pointerType === PT_TOUCH) { - if (this._mouseInViewport) { - this._mouseInViewport = false; - this._updateArrows(); - } - } - }, - - _MSPointerMove: function NavBarContainer_MSPointerMove(ev) { - if (ev.pointerType !== PT_TOUCH) { - if (!this._mouseInViewport) { - this._mouseInViewport = true; - this._updateArrows(); - } - } - }, - - _setupTree: function NavBarContainer_setupTree() { - this._animateNextPreviousButtons = Promise.wrap(); - this._element.addEventListener('mouseleave', this._mouseleave.bind(this)); - _ElementUtilities._addEventListener(this._element, 'pointerdown', this._MSPointerDown.bind(this)); - _ElementUtilities._addEventListener(this._element, 'pointermove', this._MSPointerMove.bind(this)); - _ElementUtilities._addEventListener(this._element, "focusin", this._focusHandler.bind(this), false); - - this._pageindicatorsEl = _Global.document.createElement('div'); - _ElementUtilities.addClass(this._pageindicatorsEl, NavBarContainer._ClassName.pageindicators); - this._element.appendChild(this._pageindicatorsEl); - - this._ariaStartMarker = _Global.document.createElement("div"); - this._element.appendChild(this._ariaStartMarker); - - this._viewportEl = _Global.document.createElement('div'); - _ElementUtilities.addClass(this._viewportEl, NavBarContainer._ClassName.viewport); - this._element.appendChild(this._viewportEl); - this._viewportEl.setAttribute("role", "group"); - this._viewportEl.setAttribute("aria-label", strings.navBarContainerViewportAriaLabel); - - this._boundResizeHandler = this._resizeHandler.bind(this); - _ElementUtilities._resizeNotifier.subscribe(this._element, this._boundResizeHandler); - this._viewportEl.addEventListener("mselementresize", this._resizeHandler.bind(this)); - this._viewportEl.addEventListener("scroll", this._scrollHandler.bind(this)); - this._viewportEl.addEventListener("MSManipulationStateChanged", this._MSManipulationStateChangedHandler.bind(this)); - - this._ariaEndMarker = _Global.document.createElement("div"); - this._element.appendChild(this._ariaEndMarker); - - this._surfaceEl = _Global.document.createElement('div'); - _ElementUtilities.addClass(this._surfaceEl, NavBarContainer._ClassName.surface); - this._viewportEl.appendChild(this._surfaceEl); - - this._surfaceEl.addEventListener("_invoked", this._navbarCommandInvokedHandler.bind(this)); - this._surfaceEl.addEventListener("_splittoggle", this._navbarCommandSplitToggleHandler.bind(this)); - _ElementUtilities._addEventListener(this._surfaceEl, "focusin", this._itemsFocusHandler.bind(this), false); - this._surfaceEl.addEventListener("keydown", this._keyDownHandler.bind(this)); - - // Reparent NavBarCommands which were in declarative markup - var tempEl = this.element.firstElementChild; - while (tempEl !== this._pageindicatorsEl) { - this._surfaceEl.appendChild(tempEl); - ControlProcessor.process(tempEl); - tempEl = this.element.firstElementChild; - } - - this._leftArrowEl = _Global.document.createElement('div'); - _ElementUtilities.addClass(this._leftArrowEl, NavBarContainer._ClassName.navleftarrow); - _ElementUtilities.addClass(this._leftArrowEl, NavBarContainer._ClassName.navarrow); - this._element.appendChild(this._leftArrowEl); - this._leftArrowEl.addEventListener('click', this._goLeft.bind(this)); - this._leftArrowEl.style.opacity = 0; - this._leftArrowEl.style.visibility = 'hidden'; - this._leftArrowFadeOut = Promise.wrap(); - - this._rightArrowEl = _Global.document.createElement('div'); - _ElementUtilities.addClass(this._rightArrowEl, NavBarContainer._ClassName.navrightarrow); - _ElementUtilities.addClass(this._rightArrowEl, NavBarContainer._ClassName.navarrow); - this._element.appendChild(this._rightArrowEl); - this._rightArrowEl.addEventListener('click', this._goRight.bind(this)); - this._rightArrowEl.style.opacity = 0; - this._rightArrowEl.style.visibility = 'hidden'; - this._rightArrowFadeOut = Promise.wrap(); - - this._keyboardBehavior = new _KeyboardBehavior._KeyboardBehavior(this._surfaceEl, { - scroller: this._viewportEl - }); - this._winKeyboard = new _KeyboardBehavior._WinKeyboard(this._surfaceEl); - }, - - _goRight: function NavBarContainer_goRight() { - if (this._sizes.rtl) { - this._goPrev(); - } else { - this._goNext(); - } - }, - - _goLeft: function NavBarContainer_goLeft() { - if (this._sizes.rtl) { - this._goNext(); - } else { - this._goPrev(); - } - }, - - _goNext: function NavBarContainer_goNext() { - this._measure(); - var itemsPerPage = this._sizes.rowsPerPage * this._sizes.columnsPerPage; - var targetPage = Math.min(Math.floor(this._keyboardBehavior.currentIndex / itemsPerPage) + 1, this._sizes.pages - 1); - this._keyboardBehavior.currentIndex = Math.min(itemsPerPage * targetPage, this._surfaceEl.children.length); - this._keyboardBehavior._focus(); - }, - - _goPrev: function NavBarContainer_goPrev() { - this._measure(); - var itemsPerPage = this._sizes.rowsPerPage * this._sizes.columnsPerPage; - var targetPage = Math.max(0, Math.floor(this._keyboardBehavior.currentIndex / itemsPerPage) - 1); - this._keyboardBehavior.currentIndex = Math.max(itemsPerPage * targetPage, 0); - this._keyboardBehavior._focus(); - }, - - _currentPage: { - get: function () { - if (this.layout === _UI.Orientation.horizontal) { - this._measure(); - if (this._sizes.viewportOffsetWidth > 0) { - return Math.min(this._sizes.pages - 1, Math.round(this._scrollPosition / this._sizes.viewportOffsetWidth)); - } - } - return 0; - } - }, - - _resizeHandler: function NavBarContainer_resizeHandler() { - if (this._disposed) { return; } - if (!this._measured) { return; } - var viewportResized = this.layout === _UI.Orientation.horizontal - ? this._sizes.viewportOffsetWidth !== parseFloat(_Global.getComputedStyle(this._viewportEl).width) - : this._sizes.viewportOffsetHeight !== parseFloat(_Global.getComputedStyle(this._viewportEl).height); - if (!viewportResized) { return; } - - this._measured = false; - - if (!this._pendingResize) { - this._pendingResize = true; - - this._resizeImplBound = this._resizeImplBound || this._resizeImpl.bind(this); - - this._updateAppBarReference(); - - if (this._appBarEl && this._appBarEl.winControl && !this._appBarEl.winControl.opened) { - // Do resize lazily. - Scheduler.schedule(this._resizeImplBound, Scheduler.Priority.idle, null, "WinJS.UI.NavBarContainer._resizeImpl"); - this._appBarEl.addEventListener('beforeopen', this._resizeImplBound); - } else { - // Do resize now - this._resizeImpl(); - } - } - }, - - _resizeImpl: function NavBarContainer_resizeImpl() { - if (!this._disposed && this._pendingResize) { - this._pendingResize = false; - if (this._appBarEl) { - this._appBarEl.removeEventListener('beforeopen', this._resizeImplBound); - } - - this._keyboardBehavior.currentIndex = 0; - if (this.element.contains(_Global.document.activeElement)) { - this._keyboardBehavior._focus(this._keyboardBehavior.currentIndex); - } - this._closeSplitIfOpen(); - this._ensureVisible(this._keyboardBehavior.currentIndex, true); - this._updatePageUI(); - } - }, - - _keyDownHandler: function NavBarContainer_keyDownHandler(ev) { - var keyCode = ev.keyCode; - if (!ev.altKey && (keyCode === Key.pageUp || keyCode === Key.pageDown)) { - var srcElement = ev.target; - if (_ElementUtilities._matchesSelector(srcElement, ".win-interactive, .win-interactive *")) { - return; - } - - var index = this._keyboardBehavior.currentIndex; - this._measure(); - - var sizes = this._sizes; - var page = Math.floor(index / (sizes.columnsPerPage * sizes.rowsPerPage)); - - var scrollPositionTarget = null; - if (keyCode === Key.pageUp) { - if (this.layout === _UI.Orientation.horizontal) { - var indexOfFirstItemOnPage = page * sizes.columnsPerPage * sizes.rowsPerPage; - if (index === indexOfFirstItemOnPage && this._surfaceEl.children[index].winControl._buttonEl === _Global.document.activeElement) { - // First item on page so go back 1 page. - index = index - sizes.columnsPerPage * sizes.rowsPerPage; - } else { - // Not first item on page so go to the first item on page. - index = indexOfFirstItemOnPage; - } - } else { - var currentItem = this._surfaceEl.children[index]; - var top = currentItem.offsetTop; - var bottom = top + currentItem.offsetHeight; - var scrollPosition = this._zooming ? this._zoomPosition : this._scrollPosition; - - if (top >= scrollPosition && bottom < scrollPosition + sizes.viewportOffsetHeight) { - // current item is fully on screen. - while (index > 0 && - this._surfaceEl.children[index - 1].offsetTop > scrollPosition) { - index--; - } - } - - if (this._keyboardBehavior.currentIndex === index) { - var scrollPositionForOnePageAboveItem = bottom - sizes.viewportOffsetHeight; - index = Math.max(0, index - 1); - while (index > 0 && - this._surfaceEl.children[index - 1].offsetTop > scrollPositionForOnePageAboveItem) { - index--; - } - if (index > 0) { - scrollPositionTarget = this._surfaceEl.children[index].offsetTop - this._sizes.itemMarginTop; - } else { - scrollPositionTarget = 0; - } - } - } - - index = Math.max(index, 0); - this._keyboardBehavior.currentIndex = index; - - var element = this._surfaceEl.children[index].winControl._buttonEl; - - if (scrollPositionTarget !== null) { - this._scrollTo(scrollPositionTarget); - } - - _ElementUtilities._setActive(element, this._viewportEl); - } else { - if (this.layout === _UI.Orientation.horizontal) { - var indexOfLastItemOnPage = (page + 1) * sizes.columnsPerPage * sizes.rowsPerPage - 1; - - if (index === indexOfLastItemOnPage) { - // Last item on page so go forward 1 page. - index = index + sizes.columnsPerPage * sizes.rowsPerPage; - } else { - // Not Last item on page so go to last item on page. - index = indexOfLastItemOnPage; - } - } else { - var currentItem = this._surfaceEl.children[this._keyboardBehavior.currentIndex]; - var top = currentItem.offsetTop; - var bottom = top + currentItem.offsetHeight; - var scrollPosition = this._zooming ? this._zoomPosition : this._scrollPosition; - - if (top >= scrollPosition && bottom < scrollPosition + sizes.viewportOffsetHeight) { - // current item is fully on screen. - while (index < this._surfaceEl.children.length - 1 && - this._surfaceEl.children[index + 1].offsetTop + this._surfaceEl.children[index + 1].offsetHeight < scrollPosition + sizes.viewportOffsetHeight) { - index++; - } - } - - if (index === this._keyboardBehavior.currentIndex) { - var scrollPositionForOnePageBelowItem = top + sizes.viewportOffsetHeight; - index = Math.min(this._surfaceEl.children.length - 1, index + 1); - while (index < this._surfaceEl.children.length - 1 && - this._surfaceEl.children[index + 1].offsetTop + this._surfaceEl.children[index + 1].offsetHeight < scrollPositionForOnePageBelowItem) { - index++; - } - - if (index < this._surfaceEl.children.length - 1) { - scrollPositionTarget = this._surfaceEl.children[index + 1].offsetTop - this._sizes.viewportOffsetHeight; - } else { - scrollPositionTarget = this._scrollLength - this._sizes.viewportOffsetHeight; - } - } - } - - index = Math.min(index, this._surfaceEl.children.length - 1); - this._keyboardBehavior.currentIndex = index; - - var element = this._surfaceEl.children[index].winControl._buttonEl; - - if (scrollPositionTarget !== null) { - this._scrollTo(scrollPositionTarget); - } - - try { - _ElementUtilities._setActive(element, this._viewportEl); - } catch (e) { - } - } - } - }, - - _focusHandler: function NavBarContainer_focusHandler(ev) { - var srcElement = ev.target; - if (!this._surfaceEl.contains(srcElement)) { - // Forward focus from NavBarContainer, viewport or surface to the currentIndex. - this._skipEnsureVisible = true; - this._keyboardBehavior._focus(this._keyboardBehavior.currentIndex); - } - }, - - _itemsFocusHandler: function NavBarContainer_itemsFocusHandler(ev) { - // Find the item which is being focused and scroll it to view. - var srcElement = ev.target; - if (srcElement === this._surfaceEl) { - return; - } - - while (srcElement.parentNode !== this._surfaceEl) { - srcElement = srcElement.parentNode; - } - - var index = -1; - while (srcElement) { - index++; - srcElement = srcElement.previousSibling; - } - - if (this._skipEnsureVisible) { - this._skipEnsureVisible = false; - } else { - this._ensureVisible(index); - } - }, - - _ensureVisible: function NavBarContainer_ensureVisible(index, withoutAnimation) { - this._measure(); - - if (this.layout === _UI.Orientation.horizontal) { - var page = Math.floor(index / (this._sizes.rowsPerPage * this._sizes.columnsPerPage)); - this._scrollTo(page * this._sizes.viewportOffsetWidth, withoutAnimation); - } else { - var element = this._surfaceEl.children[index]; - var maxScrollPosition; - if (index > 0) { - maxScrollPosition = element.offsetTop - this._sizes.itemMarginTop; - } else { - maxScrollPosition = 0; - } - var minScrollPosition; - if (index < this._surfaceEl.children.length - 1) { - minScrollPosition = this._surfaceEl.children[index + 1].offsetTop - this._sizes.viewportOffsetHeight; - } else { - minScrollPosition = this._scrollLength - this._sizes.viewportOffsetHeight; - } - - var newScrollPosition = this._zooming ? this._zoomPosition : this._scrollPosition; - newScrollPosition = Math.max(newScrollPosition, minScrollPosition); - newScrollPosition = Math.min(newScrollPosition, maxScrollPosition); - this._scrollTo(newScrollPosition, withoutAnimation); - } - }, - - _scrollTo: function NavBarContainer_scrollTo(targetScrollPosition, withoutAnimation) { - this._measure(); - if (this.layout === _UI.Orientation.horizontal) { - targetScrollPosition = Math.max(0, Math.min(this._scrollLength - this._sizes.viewportOffsetWidth, targetScrollPosition)); - } else { - targetScrollPosition = Math.max(0, Math.min(this._scrollLength - this._sizes.viewportOffsetHeight, targetScrollPosition)); - } - - if (withoutAnimation) { - if (Math.abs(this._scrollPosition - targetScrollPosition) > 1) { - this._zooming = false; - - this._scrollPosition = targetScrollPosition; - this._updatePageUI(); - if (!this._duringForceLayout) { - this._closeSplitIfOpen(); - } - - var newScrollPos = {}; - newScrollPos[(this.layout === _UI.Orientation.horizontal ? "scrollLeft" : "scrollTop")] = targetScrollPosition; - _ElementUtilities.setScrollPosition(this._viewportEl, newScrollPos); - } - } else { - if ((!this._zooming && Math.abs(this._scrollPosition - targetScrollPosition) > 1) || (this._zooming && Math.abs(this._zoomPosition - targetScrollPosition) > 1)) { - this._zoomPosition = targetScrollPosition; - - this._zooming = true; - - if (this.layout === _UI.Orientation.horizontal) { - this._viewportEl.style.msScrollSnapType = "none"; - _ElementUtilities._zoomTo(this._viewportEl, { contentX: targetScrollPosition, contentY: 0, viewportX: 0, viewportY: 0 }); - } else { - _ElementUtilities._zoomTo(this._viewportEl, { contentX: 0, contentY: targetScrollPosition, viewportX: 0, viewportY: 0 }); - } - - this._closeSplitIfOpen(); - } - } - }, - - _MSManipulationStateChangedHandler: function NavBarContainer_MSManipulationStateChangedHandler(e) { - this._currentManipulationState = e.currentState; - - if (e.currentState === e.MS_MANIPULATION_STATE_ACTIVE) { - this._viewportEl.style.msScrollSnapType = ""; - this._zooming = false; - } - - _Global.clearTimeout(this._manipulationStateTimeoutId); - // The extra stop event is firing when an zoomTo is called during another zoomTo and - // also the first zoomTo after a resize. - if (e.currentState === e.MS_MANIPULATION_STATE_STOPPED) { - this._manipulationStateTimeoutId = _Global.setTimeout(function () { - this._viewportEl.style.msScrollSnapType = ""; - this._zooming = false; - this._updateCurrentIndexIfPageChanged(); - }.bind(this), 100); - } - }, - - _scrollHandler: function NavBarContainer_scrollHandler() { - if (this._disposed) { return; } - - this._measured = false; - if (!this._checkingScroll) { - var that = this; - this._checkingScroll = _BaseUtils._requestAnimationFrame(function () { - if (that._disposed) { return; } - that._checkingScroll = null; - - var newScrollPosition = _ElementUtilities.getScrollPosition(that._viewportEl)[(that.layout === _UI.Orientation.horizontal ? "scrollLeft" : "scrollTop")]; - if (newScrollPosition !== that._scrollPosition) { - that._scrollPosition = newScrollPosition; - that._closeSplitIfOpen(); - } - that._updatePageUI(); - - if (!that._zooming && that._currentManipulationState === MS_MANIPULATION_STATE_STOPPED) { - that._updateCurrentIndexIfPageChanged(); - } - }); - } - }, - - _updateCurrentIndexIfPageChanged: function NavBarContainer_updateCurrentIndexIfPageChanged() { - // If you change pages via pagination arrows, mouse wheel, or panning we need to update the current - // item to be the first item on the new page. - if (this.layout === _UI.Orientation.horizontal) { - this._measure(); - var currentPage = this._currentPage; - var firstIndexOnPage = currentPage * this._sizes.rowsPerPage * this._sizes.columnsPerPage; - var lastIndexOnPage = (currentPage + 1) * this._sizes.rowsPerPage * this._sizes.columnsPerPage - 1; - - if (this._keyboardBehavior.currentIndex < firstIndexOnPage || this._keyboardBehavior.currentIndex > lastIndexOnPage) { - // Page change occurred. - this._keyboardBehavior.currentIndex = firstIndexOnPage; - - if (this.element.contains(_Global.document.activeElement)) { - this._keyboardBehavior._focus(this._keyboardBehavior.currentIndex); - } - } - } - }, - - _measure: function NavBarContainer_measure() { - if (!this._measured) { - this._resizeImpl(); - this._writeProfilerMark("measure,StartTM"); - - var sizes = this._sizes; - - sizes.rtl = _Global.getComputedStyle(this._element).direction === "rtl"; - - var itemCount = this._surfaceEl.children.length; - if (itemCount > 0) { - if (!this._sizes.itemMeasured) { - this._writeProfilerMark("measureItem,StartTM"); - - var elementToMeasure = this._surfaceEl.firstElementChild; - // Clear inline margins set by NavBarContainer before measuring. - elementToMeasure.style.margin = ""; - elementToMeasure.style.width = ""; - var elementComputedStyle = _Global.getComputedStyle(elementToMeasure); - sizes.itemOffsetWidth = parseFloat(_Global.getComputedStyle(elementToMeasure).width); - if (elementToMeasure.offsetWidth === 0) { - sizes.itemOffsetWidth = 0; - } - sizes.itemMarginLeft = parseFloat(elementComputedStyle.marginLeft); - sizes.itemMarginRight = parseFloat(elementComputedStyle.marginRight); - sizes.itemWidth = sizes.itemOffsetWidth + sizes.itemMarginLeft + sizes.itemMarginRight; - sizes.itemOffsetHeight = parseFloat(_Global.getComputedStyle(elementToMeasure).height); - if (elementToMeasure.offsetHeight === 0) { - sizes.itemOffsetHeight = 0; - } - sizes.itemMarginTop = parseFloat(elementComputedStyle.marginTop); - sizes.itemMarginBottom = parseFloat(elementComputedStyle.marginBottom); - sizes.itemHeight = sizes.itemOffsetHeight + sizes.itemMarginTop + sizes.itemMarginBottom; - if (sizes.itemOffsetWidth > 0 && sizes.itemOffsetHeight > 0) { - sizes.itemMeasured = true; - } - this._writeProfilerMark("measureItem,StopTM"); - } - - sizes.viewportOffsetWidth = parseFloat(_Global.getComputedStyle(this._viewportEl).width); - if (this._viewportEl.offsetWidth === 0) { - sizes.viewportOffsetWidth = 0; - } - sizes.viewportOffsetHeight = parseFloat(_Global.getComputedStyle(this._viewportEl).height); - if (this._viewportEl.offsetHeight === 0) { - sizes.viewportOffsetHeight = 0; - } - - if (sizes.viewportOffsetWidth === 0 || sizes.itemOffsetHeight === 0) { - this._measured = false; - } else { - this._measured = true; - } - - if (this.layout === _UI.Orientation.horizontal) { - this._scrollPosition = _ElementUtilities.getScrollPosition(this._viewportEl).scrollLeft; - - sizes.leadingEdge = this._leftArrowEl.offsetWidth + parseInt(_Global.getComputedStyle(this._leftArrowEl).marginLeft) + parseInt(_Global.getComputedStyle(this._leftArrowEl).marginRight); - var usableSpace = sizes.viewportOffsetWidth - sizes.leadingEdge * 2; - sizes.maxColumns = sizes.itemWidth ? Math.max(1, Math.floor(usableSpace / sizes.itemWidth)) : 1; - sizes.rowsPerPage = Math.min(this.maxRows, Math.ceil(itemCount / sizes.maxColumns)); - sizes.columnsPerPage = Math.min(sizes.maxColumns, itemCount); - sizes.pages = Math.ceil(itemCount / (sizes.columnsPerPage * sizes.rowsPerPage)); - sizes.trailingEdge = sizes.leadingEdge; - sizes.extraSpace = usableSpace - (sizes.columnsPerPage * sizes.itemWidth); - - this._scrollLength = sizes.viewportOffsetWidth * sizes.pages; - - this._keyboardBehavior.fixedSize = sizes.rowsPerPage; - this._keyboardBehavior.fixedDirection = _KeyboardBehavior._KeyboardBehavior.FixedDirection.height; - - this._surfaceEl.style.height = (sizes.itemHeight * sizes.rowsPerPage) + "px"; - this._surfaceEl.style.width = this._scrollLength + "px"; - } else { - this._scrollPosition = this._viewportEl.scrollTop; - - sizes.leadingEdge = 0; - sizes.rowsPerPage = itemCount; - sizes.columnsPerPage = 1; - sizes.pages = 1; - sizes.trailingEdge = 0; - - // Reminder there is margin collapsing so just use scrollHeight instead of itemHeight * itemCount - this._scrollLength = this._viewportEl.scrollHeight; - - this._keyboardBehavior.fixedSize = sizes.columnsPerPage; - this._keyboardBehavior.fixedDirection = _KeyboardBehavior._KeyboardBehavior.FixedDirection.width; - - this._surfaceEl.style.height = ""; - this._surfaceEl.style.width = ""; - } - - this._updateGridStyles(); - } else { - sizes.pages = 1; - this._hasPreviousContent = false; - this._hasNextContent = false; - this._surfaceEl.style.height = ""; - this._surfaceEl.style.width = ""; - } - - this._writeProfilerMark("measure,StopTM"); - } - }, - - _updateGridStyles: function NavBarContainer_updateGridStyles() { - var sizes = this._sizes; - var itemCount = this._surfaceEl.children.length; - - for (var index = 0; index < itemCount; index++) { - var itemEl = this._surfaceEl.children[index]; - - var marginRight; - var marginLeft; - var width = ""; - - if (this.layout === _UI.Orientation.horizontal) { - var column = Math.floor(index / sizes.rowsPerPage); - var isFirstColumnOnPage = column % sizes.columnsPerPage === 0; - var isLastColumnOnPage = column % sizes.columnsPerPage === sizes.columnsPerPage - 1; - - var extraTrailingMargin = sizes.trailingEdge; - if (this.fixedSize) { - extraTrailingMargin += sizes.extraSpace; - } else { - var spaceToDistribute = sizes.extraSpace - (sizes.maxColumns - sizes.columnsPerPage) * sizes.itemWidth; - width = (sizes.itemOffsetWidth + (spaceToDistribute / sizes.maxColumns)) + "px"; - } - - var extraMarginRight; - var extraMarginLeft; - - if (sizes.rtl) { - extraMarginRight = (isFirstColumnOnPage ? sizes.leadingEdge : 0); - extraMarginLeft = (isLastColumnOnPage ? extraTrailingMargin : 0); - } else { - extraMarginRight = (isLastColumnOnPage ? extraTrailingMargin : 0); - extraMarginLeft = (isFirstColumnOnPage ? sizes.leadingEdge : 0); - } - - marginRight = extraMarginRight + sizes.itemMarginRight + "px"; - marginLeft = extraMarginLeft + sizes.itemMarginLeft + "px"; - } else { - marginRight = ""; - marginLeft = ""; - } - - if (itemEl.style.marginRight !== marginRight) { - itemEl.style.marginRight = marginRight; - } - if (itemEl.style.marginLeft !== marginLeft) { - itemEl.style.marginLeft = marginLeft; - } - if (itemEl.style.width !== width) { - itemEl.style.width = width; - } - } - }, - - _updatePageUI: function NavBarContainer_updatePageUI() { - this._measure(); - var currentPage = this._currentPage; - - this._hasPreviousContent = (currentPage !== 0); - this._hasNextContent = (currentPage < this._sizes.pages - 1); - this._updateArrows(); - - // Always output the pagination indicators so they reserves up space. - if (this._indicatorCount !== this._sizes.pages) { - this._indicatorCount = this._sizes.pages; - this._pageindicatorsEl.innerHTML = new Array(this._sizes.pages + 1).join(''); - } - - for (var i = 0; i < this._pageindicatorsEl.children.length; i++) { - if (i === currentPage) { - _ElementUtilities.addClass(this._pageindicatorsEl.children[i], NavBarContainer._ClassName.currentindicator); - } else { - _ElementUtilities.removeClass(this._pageindicatorsEl.children[i], NavBarContainer._ClassName.currentindicator); - } - } - - if (this._sizes.pages > 1) { - this._viewportEl.style.overflowX = this._panningDisabled ? "hidden" : ""; - this._pageindicatorsEl.style.visibility = ""; - } else { - this._viewportEl.style.overflowX = "hidden"; - this._pageindicatorsEl.style.visibility = "hidden"; - } - - if (this._sizes.pages <= 1 || this._layout !== _UI.Orientation.horizontal) { - this._ariaStartMarker.removeAttribute("aria-flowto"); - this._ariaEndMarker.removeAttribute("x-ms-aria-flowfrom"); - } else { - var firstIndexOnCurrentPage = currentPage * this._sizes.rowsPerPage * this._sizes.columnsPerPage; - var firstItem = this._surfaceEl.children[firstIndexOnCurrentPage].winControl._buttonEl; - _ElementUtilities._ensureId(firstItem); - this._ariaStartMarker.setAttribute("aria-flowto", firstItem.id); - - var lastIndexOnCurrentPage = Math.min(this._surfaceEl.children.length - 1, (currentPage + 1) * this._sizes.rowsPerPage * this._sizes.columnsPerPage - 1); - var lastItem = this._surfaceEl.children[lastIndexOnCurrentPage].winControl._buttonEl; - _ElementUtilities._ensureId(lastItem); - this._ariaEndMarker.setAttribute("x-ms-aria-flowfrom", lastItem.id); - } - }, - - _closeSplitIfOpen: function NavBarContainer_closeSplitIfOpen() { - if (this._currentSplitNavItem) { - if (this._currentSplitNavItem.splitOpened) { - this._currentSplitNavItem._toggleSplit(); - } - this._currentSplitNavItem = null; - } - }, - - _updateArrows: function NavBarContainer_updateArrows() { - var hasLeftContent = this._sizes.rtl ? this._hasNextContent : this._hasPreviousContent; - var hasRightContent = this._sizes.rtl ? this._hasPreviousContent : this._hasNextContent; - - var that = this; - // Previous and next are the arrows, not states. On mouse hover the arrows fade in immediately. If you - // mouse out the arrows fade out after a delay. When you reach the last/first page, the corresponding - // arrow fades out immediately as well. - if ((this._mouseInViewport || this._panningDisabled) && hasLeftContent) { - this._leftArrowWaitingToFadeOut && this._leftArrowWaitingToFadeOut.cancel(); - this._leftArrowWaitingToFadeOut = null; - this._leftArrowFadeOut && this._leftArrowFadeOut.cancel(); - this._leftArrowFadeOut = null; - this._leftArrowEl.style.visibility = ''; - this._leftArrowFadeIn = this._leftArrowFadeIn || Animations.fadeIn(this._leftArrowEl); - } else { - if (hasLeftContent) { - // If we need a delayed fade out and we are already running a delayed fade out just use that one, don't extend it. - // Otherwise create a delayed fade out. - this._leftArrowWaitingToFadeOut = this._leftArrowWaitingToFadeOut || Promise.timeout(_TransitionAnimation._animationTimeAdjustment(buttonFadeDelay)); - } else { - // If we need a immediate fade out and already have a delayed fade out cancel that one and create an immediate one. - this._leftArrowWaitingToFadeOut && this._leftArrowWaitingToFadeOut.cancel(); - this._leftArrowWaitingToFadeOut = Promise.wrap(); - } - this._leftArrowWaitingToFadeOut.then(function () { - // After the delay cancel any fade in if running. If we already were fading out continue it otherwise start the fade out. - this._leftArrowFadeIn && this._leftArrowFadeIn.cancel(); - this._leftArrowFadeIn = null; - this._leftArrowFadeOut = this._leftArrowFadeOut || Animations.fadeOut(this._leftArrowEl).then(function () { - that._leftArrowEl.style.visibility = 'hidden'; - }); - }.bind(this)); - } - - // Same pattern for Next arrow. - if ((this._mouseInViewport || this._panningDisabled) && hasRightContent) { - this._rightArrowWaitingToFadeOut && this._rightArrowWaitingToFadeOut.cancel(); - this._rightArrowWaitingToFadeOut = null; - this._rightArrowFadeOut && this._rightArrowFadeOut.cancel(); - this._rightArrowFadeOut = null; - this._rightArrowEl.style.visibility = ''; - this._rightArrowFadeIn = this._rightArrowFadeIn || Animations.fadeIn(this._rightArrowEl); - } else { - if (hasRightContent) { - this._rightArrowWaitingToFadeOut = this._rightArrowWaitingToFadeOut || Promise.timeout(_TransitionAnimation._animationTimeAdjustment(buttonFadeDelay)); - } else { - this._rightArrowWaitingToFadeOut && this._rightArrowWaitingToFadeOut.cancel(); - this._rightArrowWaitingToFadeOut = Promise.wrap(); - } - this._rightArrowWaitingToFadeOut.then(function () { - this._rightArrowFadeIn && this._rightArrowFadeIn.cancel(); - this._rightArrowFadeIn = null; - this._rightArrowFadeOut = this._rightArrowFadeOut || Animations.fadeOut(this._rightArrowEl).then(function () { - that._rightArrowEl.style.visibility = 'hidden'; - }); - }.bind(this)); - } - }, - - _navbarCommandInvokedHandler: function NavBarContainer_navbarCommandInvokedHandler(ev) { - var srcElement = ev.target; - var index = -1; - while (srcElement) { - index++; - srcElement = srcElement.previousSibling; - } - - this._fireEvent(NavBarContainer._EventName.invoked, { - index: index, - navbarCommand: ev.target.winControl, - data: this._repeater ? this._repeater.data.getAt(index) : null - }); - }, - - _navbarCommandSplitToggleHandler: function NavBarContainer_navbarCommandSplitToggleHandler(ev) { - var srcElement = ev.target; - var index = -1; - while (srcElement) { - index++; - srcElement = srcElement.previousSibling; - } - - var navbarCommand = ev.target.winControl; - - this._closeSplitIfOpen(); - - if (navbarCommand.splitOpened) { - this._currentSplitNavItem = navbarCommand; - } - - this._fireEvent(NavBarContainer._EventName.splitToggle, { - opened: navbarCommand.splitOpened, - index: index, - navbarCommand: navbarCommand, - data: this._repeater ? this._repeater.data.getAt(index) : null - }); - }, - - _fireEvent: function NavBarContainer_fireEvent(type, detail) { - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(type, true, false, detail); - this.element.dispatchEvent(event); - }, - - _writeProfilerMark: function NavBarContainer_writeProfilerMark(text) { - var message = "WinJS.UI.NavBarContainer:" + this._id + ":" + text; - _WriteProfilerMark(message); - _Log.log && _Log.log(message, null, "navbarcontainerprofiler"); - }, - - dispose: function NavBarContainer_dispose() { - /// - /// - /// Disposes this control. - /// - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - - if (this._appBarEl) { - this._appBarEl.removeEventListener('beforeopen', this._closeSplitAndResetBound); - this._appBarEl.removeEventListener('beforeopen', this._resizeImplBound); - } - - Navigation.removeEventListener('navigated', this._closeSplitAndResetBound); - - this._leftArrowWaitingToFadeOut && this._leftArrowWaitingToFadeOut.cancel(); - this._leftArrowFadeOut && this._leftArrowFadeOut.cancel(); - this._leftArrowFadeIn && this._leftArrowFadeIn.cancel(); - this._rightArrowWaitingToFadeOut && this._rightArrowWaitingToFadeOut.cancel(); - this._rightArrowFadeOut && this._rightArrowFadeOut.cancel(); - this._rightArrowFadeIn && this._rightArrowFadeIn.cancel(); - - _ElementUtilities._resizeNotifier.unsubscribe(this._element, this._boundResizeHandler); - - this._removeDataChangingEvents(); - this._removeDataChangedEvents(); - } - }, { - // Names of classes used by the NavBarContainer. - _ClassName: { - navbarcontainer: "win-navbarcontainer", - pageindicators: "win-navbarcontainer-pageindicator-box", - indicator: "win-navbarcontainer-pageindicator", - currentindicator: "win-navbarcontainer-pageindicator-current", - vertical: "win-navbarcontainer-vertical", - horizontal: "win-navbarcontainer-horizontal", - viewport: "win-navbarcontainer-viewport", - surface: "win-navbarcontainer-surface", - navarrow: "win-navbarcontainer-navarrow", - navleftarrow: "win-navbarcontainer-navleft", - navrightarrow: "win-navbarcontainer-navright" - }, - _EventName: { - invoked: eventNames.invoked, - splitToggle: eventNames.splittoggle - } - }); - _Base.Class.mix(NavBarContainer, _Control.DOMEventMixin); - return NavBarContainer; - }) - }); - -}); - - -define('require-style!less/styles-navbar',[],function(){}); - -define('require-style!less/colors-navbar',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/NavBar',[ - '../Core/_Global', - '../Core/_WinRT', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_Events', - '../Core/_WriteProfilerMark', - '../Promise', - '../Scheduler', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - "../_Accents", - './_LegacyAppBar', - './NavBar/_Command', - './NavBar/_Container', - 'require-style!less/styles-navbar', - 'require-style!less/colors-navbar' -], function NavBarInit(_Global,_WinRT, _Base, _BaseUtils, _Events, _WriteProfilerMark, Promise, Scheduler, _ElementUtilities, _Hoverable, _Accents, _LegacyAppBar, _Command, _Container) { - "use strict"; - - _Accents.createAccentRule("html.win-hoverable .win-navbarcommand-splitbutton.win-navbarcommand-splitbutton-opened:hover", [{ name: "background-color", value: _Accents.ColorTypes.listSelectHover }]); - _Accents.createAccentRule("html.win-hoverable .win-navbarcommand-splitbutton.win-navbarcommand-splitbutton-opened:hover.win-pressed", [{ name: "background-color", value: _Accents.ColorTypes.listSelectPress }]); - _Accents.createAccentRule(".win-navbarcommand-splitbutton.win-navbarcommand-splitbutton-opened", [{ name: "background-color", value: _Accents.ColorTypes.listSelectRest }]); - _Accents.createAccentRule(".win-navbarcommand-splitbutton.win-navbarcommand-splitbutton-opened.win-pressed", [{ name: "background-color", value: _Accents.ColorTypes.listSelectPress }]); - - var customLayout = "custom"; - - _Base.Namespace.define("WinJS.UI", { - /// - /// - /// Displays navigation commands in a toolbar that the user can open or close. - /// - /// - /// - /// - /// - /// - ///
- ///
- ///
- /// ]]>
- /// Raised just before opening the NavBar. - /// Raised immediately after an NavBar is fully opened. - /// Raised just before closing the NavBar. - /// Raised immediately after the NavBar is fully closed. - /// Fired when children of NavBar control have been processed from a WinJS.UI.processAll call. - /// Styles the entire NavBar. - /// - /// - NavBar: _Base.Namespace._lazy(function () { - var childrenProcessedEventName = "childrenprocessed"; - var createEvent = _Events._createEventProperty; - - var NavBar = _Base.Class.derive(_LegacyAppBar._LegacyAppBar, function NavBar_ctor(element, options) { - /// - /// - /// Creates a new NavBar. - /// - /// - /// The DOM element that will host the new NavBar control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. Each property of the options object corresponds to one of the control's - /// properties or events. - /// - /// - /// The new NavBar control. - /// - /// - /// - - options = options || {}; - - // Shallow copy object so we can modify it. - options = _BaseUtils._shallowCopy(options); - - // Default to Placement = Top and Layout = Custom - options.placement = options.placement || "top"; - options.layout = customLayout; - options.closedDisplayMode = options.closedDisplayMode || "minimal"; - - _LegacyAppBar._LegacyAppBar.call(this, element, options); - - this._element.addEventListener("beforeopen", this._handleBeforeShow.bind(this)); - - _ElementUtilities.addClass(this.element, NavBar._ClassName.navbar); - - if (_WinRT.Windows.ApplicationModel.DesignMode.designModeEnabled) { - this._processChildren(); - } else { - Scheduler.schedule(this._processChildren.bind(this), Scheduler.Priority.idle, null, "WinJS.UI.NavBar.processChildren"); - } - }, { - - // Restrict values of closedDisplayMode to 'none' or 'minimal' - - /// - /// Gets/Sets how NavBar will display itself while hidden. Values are "none" and "minimal". - /// - closedDisplayMode: { - get: function () { - return this._closedDisplayMode; - }, - set: function (value) { - var newValue = (value === "none" ? "none" : "minimal"); - Object.getOwnPropertyDescriptor(_LegacyAppBar._LegacyAppBar.prototype, "closedDisplayMode").set.call(this, newValue); - this._closedDisplayMode = newValue; - }, - }, - - /// - /// Raised when children of NavBar control have been processed by a WinJS.UI.processAll call. - /// - /// - onchildrenprocessed: createEvent(childrenProcessedEventName), - - _processChildren: function NavBar_processChildren() { - // The NavBar control schedules processAll on its children at idle priority to avoid hurting startup - // performance. If the NavBar is shown before the scheduler gets to the idle job, the NavBar will - // immediately call processAll on its children. If your app needs the children to be processed before - // the scheduled job executes, you may call processChildren to force the processAll call. - if (!this._processed) { - this._processed = true; - - this._writeProfilerMark("processChildren,StartTM"); - var that = this; - var processed = Promise.as(); - if (this._processors) { - this._processors.forEach(function (processAll) { - for (var i = 0, len = that.element.children.length; i < len; i++) { - (function (child) { - processed = processed.then(function () { - processAll(child); - }); - }(that.element.children[i])); - } - }); - } - return processed.then( - function () { - that._writeProfilerMark("processChildren,StopTM"); - that._fireEvent(NavBar._EventName.childrenProcessed); - }, - function () { - that._writeProfilerMark("processChildren,StopTM"); - that._fireEvent(NavBar._EventName.childrenProcessed); - } - ); - } - return Promise.wrap(); - }, - - _show: function NavBar_show() { - // Override _show to call processChildren first. - // - if (this.disabled) { - return; - } - var that = this; - this._processChildren().then(function () { - _LegacyAppBar._LegacyAppBar.prototype._show.call(that); - }); - }, - - _handleBeforeShow: function NavBar_handleBeforeShow() { - // Navbar needs to ensure its elements to have their correct height and width after _LegacyAppBar changes display="none" - // to display="" and _LegacyAppBar needs the elements to have their final height before it measures its own element height - // to do the slide in animation over the correct amount of pixels. - if (this._disposed) { - return; - } - - var navbarcontainerEls = this.element.querySelectorAll('.win-navbarcontainer'); - for (var i = 0; i < navbarcontainerEls.length; i++) { - navbarcontainerEls[i].winControl.forceLayout(); - } - }, - - _fireEvent: function NavBar_fireEvent(type, detail) { - var event = _Global.document.createEvent("CustomEvent"); - event.initCustomEvent(type, true, false, detail || {}); - this.element.dispatchEvent(event); - }, - - _writeProfilerMark: function NavBar_writeProfilerMark(text) { - _WriteProfilerMark("WinJS.UI.NavBar:" + this._id + ":" + text); - } - }, { - _ClassName: { - navbar: "win-navbar" - }, - _EventName: { - childrenProcessed: childrenProcessedEventName - }, - isDeclarativeControlContainer: _BaseUtils.markSupportedForProcessing(function (navbar, callback) { - if (navbar._processed) { - for (var i = 0, len = navbar.element.children.length; i < len; i++) { - callback(navbar.element.children[i]); - } - } else { - navbar._processors = navbar._processors || []; - navbar._processors.push(callback); - } - }) - }); - - return NavBar; - }) - }); - -}); - -define('require-style!less/styles-viewbox',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -// ViewBox control -define('WinJS/Controls/ViewBox',[ - '../Core/_Global', - '../Core/_Base', - '../Core/_BaseUtils', - '../Core/_ErrorFromName', - '../Core/_Resources', - '../Scheduler', - '../Utilities/_Control', - '../Utilities/_Dispose', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - 'require-style!less/styles-viewbox' - ], function viewboxInit(_Global, _Base, _BaseUtils, _ErrorFromName, _Resources, Scheduler, _Control, _Dispose, _ElementUtilities, _Hoverable) { - "use strict"; - - _Base.Namespace.define("WinJS.UI", { - /// - /// - /// Scales a single child element to fill the available space without - /// resizing it. This control reacts to changes in the size of the container as well as - /// changes in size of the child element. For example, a media query may result in - /// a change in aspect ratio. - /// - /// - /// View Box - /// - /// - ///
ViewBox
]]>
- /// - /// - ViewBox: _Base.Namespace._lazy(function () { - - var strings = { - get invalidViewBoxChildren() { return "ViewBox expects to only have one child element"; }, - }; - - function onresize(control) { - if (control && !control._resizing) { - control._resizing = control._resizing || 0; - control._resizing++; - try { - control._updateLayout(); - } finally { - control._resizing--; - } - } - } - - function onresizeBox(ev) { - if (ev.target) { - onresize(ev.target.winControl); - } - } - - function onresizeSizer(ev) { - if (ev.target) { - onresize(ev.target.parentElement.winControl); - } - } - - var ViewBox = _Base.Class.define(function ViewBox_ctor(element) { - /// - /// Initializes a new instance of the ViewBox control - /// - /// The DOM element that functions as the scaling box. This element fills 100% of the width and height allotted to it. - /// - /// - /// The set of options to be applied initially to the ViewBox control. - /// - /// A constructed ViewBox control. - /// - this._disposed = false; - - this._element = element || _Global.document.createElement("div"); - var box = this.element; - box.winControl = this; - _ElementUtilities.addClass(box, "win-disposable"); - _ElementUtilities.addClass(box, "win-viewbox"); - this.forceLayout(); - }, { - _sizer: null, - _element: null, - - /// - element: { - get: function () { return this._element; } - }, - - _rtl: { - get: function () { - return _Global.getComputedStyle(this.element).direction === "rtl"; - } - }, - - _initialize: function () { - var box = this.element; - if (box.firstElementChild !== this._sizer) { - if (_BaseUtils.validation) { - if (box.childElementCount !== 1) { - throw new _ErrorFromName("WinJS.UI.ViewBox.InvalidChildren", strings.invalidViewBoxChildren); - } - } - if (this._sizer) { - this._sizer.onresize = null; - } - var sizer = box.firstElementChild; - this._sizer = sizer; - if (sizer) { - _ElementUtilities._resizeNotifier.subscribe(box, onresizeBox); - box.addEventListener("mselementresize", onresizeBox); - _ElementUtilities._resizeNotifier.subscribe(sizer, onresizeSizer); - sizer.addEventListener("mselementresize", onresizeSizer); - } - if (box.clientWidth === 0 && box.clientHeight === 0) { - var that = this; - // Wait for the viewbox to get added to the DOM. It should be added - // in the synchronous block in which _initialize was called. - Scheduler.schedule(function ViewBox_async_initialize() { - that._updateLayout(); - }, Scheduler.Priority.normal, null, "WinJS.UI.ViewBox._updateLayout"); - } - } - }, - _updateLayout: function () { - var sizer = this._sizer; - if (sizer) { - var box = this.element; - var w = sizer.clientWidth; - var h = sizer.clientHeight; - var bw = box.clientWidth; - var bh = box.clientHeight; - var wRatio = bw / w; - var hRatio = bh / h; - var mRatio = Math.min(wRatio, hRatio); - var transX = Math.abs(bw - (w * mRatio)) / 2; - var transY = Math.abs(bh - (h * mRatio)) / 2; - var rtl = this._rtl; - this._sizer.style[_BaseUtils._browserStyleEquivalents["transform"].scriptName] = "translate(" + (rtl ? "-" : "") + transX + "px," + transY + "px) scale(" + mRatio + ")"; - this._sizer.style[_BaseUtils._browserStyleEquivalents["transform-origin"].scriptName] = rtl ? "top right" : "top left"; - } - }, - - dispose: function () { - /// - /// - /// Disposes this ViewBox. - /// - /// - if (this._disposed) { - return; - } - - if (this.element) { - _ElementUtilities._resizeNotifier.unsubscribe(this.element, onresizeBox); - } - if (this._sizer) { - _ElementUtilities._resizeNotifier.unsubscribe(this._sizer, onresizeSizer); - } - - this._disposed = true; - _Dispose.disposeSubTree(this._element); - }, - - forceLayout: function () { - this._initialize(); - this._updateLayout(); - } - }); - _Base.Class.mix(ViewBox, _Control.DOMEventMixin); - return ViewBox; - }) - }); - -}); - - -define('require-style!less/styles-contentdialog',[],function(){}); - -define('require-style!less/colors-contentdialog',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('WinJS/Controls/ContentDialog',[ - '../Application', - '../Utilities/_Dispose', - '../_Accents', - '../Promise', - '../_Signal', - '../_LightDismissService', - '../Core/_BaseUtils', - '../Core/_Global', - '../Core/_WinRT', - '../Core/_Base', - '../Core/_Events', - '../Core/_ErrorFromName', - '../Core/_Resources', - '../Utilities/_Control', - '../Utilities/_ElementUtilities', - '../Utilities/_Hoverable', - '../Animations', - 'require-style!less/styles-contentdialog', - 'require-style!less/colors-contentdialog' -], function contentDialogInit(Application, _Dispose, _Accents, Promise, _Signal, _LightDismissService, _BaseUtils, _Global, _WinRT, _Base, _Events, _ErrorFromName, _Resources, _Control, _ElementUtilities, _Hoverable, _Animations) { - "use strict"; - - _Accents.createAccentRule(".win-contentdialog-dialog", [{ name: "outline-color", value: _Accents.ColorTypes.accent }]); - - _Base.Namespace.define("WinJS.UI", { - /// - /// - /// Displays a modal dialog which can display arbitrary HTML content. - /// - /// - /// - /// - /// ]]> - /// Raised just before showing a dialog. Call preventDefault on this event to stop the dialog from being shown. - /// Raised immediately after a dialog is fully shown. - /// Raised just before hiding a dialog. Call preventDefault on this event to stop the dialog from being hidden. - /// Raised immediately after a dialog is fully hidden. - /// The entire ContentDialog control. - /// The full screen element which dims the content that is behind the dialog. - /// The main element of the dialog which holds the dialog's title, content, and commands. - /// The element which displays the dialog's title. - /// The element which contains the dialog's custom content. - /// The element which contains the dialog's primary and secondary commands. - /// The dialog's primary button. - /// The dialog's secondary button. - /// - /// - ContentDialog: _Base.Namespace._lazy(function () { - var Strings = { - get duplicateConstruction() { return "Invalid argument: Controls may only be instantiated one time for each DOM element"; }, - get controlDisposed() { return "Cannot interact with the control after it has been disposed"; }, - get contentDialogAlreadyShowing() { return "Cannot show a ContentDialog if there is already a ContentDialog that is showing"; } - }; - var DismissalResult = { - /// - /// The dialog was dismissed without the user selecting any of the commands. The user may have - /// dismissed the dialog by hitting the escape key or pressing the hardware back button. - /// - none: "none", - /// - /// The user dismissed the dialog by pressing the primary command. - /// - primary: "primary", - /// - /// The user dismissed the dialog by pressing the secondary command. - /// - secondary: "secondary" - }; - var ClassNames = { - contentDialog: "win-contentdialog", - backgroundOverlay: "win-contentdialog-backgroundoverlay", - dialog: "win-contentdialog-dialog", - title: "win-contentdialog-title", - content: "win-contentdialog-content", - commands: "win-contentdialog-commands", - primaryCommand: "win-contentdialog-primarycommand", - secondaryCommand: "win-contentdialog-secondarycommand", - - _verticalAlignment: "win-contentdialog-verticalalignment", - _scroller: "win-contentdialog-scroller", - _column0or1: "win-contentdialog-column0or1", - _visible: "win-contentdialog-visible", - _tabStop: "win-contentdialog-tabstop", - _commandSpacer: "win-contentdialog-commandspacer" - }; - var EventNames = { - beforeShow: "beforeshow", - afterShow: "aftershow", - beforeHide: "beforehide", - afterHide: "afterhide", - }; - var minContentHeightWithInputPane = 96; - - // WinJS animation promises always complete successfully. This - // helper allows an animation promise to complete in the canceled state - // so that the success handler can be skipped when the animation is - // interrupted. - function cancelablePromise(animationPromise) { - return Promise._cancelBlocker(animationPromise, function () { - animationPromise.cancel(); - }); - } - - function onInputPaneShown(eventObject) { - /*jshint validthis: true */ - eventObject.ensuredFocusedElementInView = true; - this.dialog._renderForInputPane(eventObject.occludedRect.height); - } - - function onInputPaneHidden() { - /*jshint validthis: true */ - this.dialog._clearInputPaneRendering(); - } - - // Noop function, used in the various states to indicate that they don't support a given - // message. Named with the somewhat cute name '_' because it reads really well in the states. - - function _() { } - - // Implementing the control as a state machine helps us correctly handle: - // - re-entrancy while firing events - // - calls into the control during asynchronous operations (e.g. animations) - // - // Many of the states do their "enter" work within a promise chain. The idea is that if - // the state is interrupted and exits, the rest of its work can be skipped by canceling - // the promise chain. - // An interesting detail is that anytime the state may call into app code (e.g. due to - // firing an event), the current promise must end and a new promise must be chained off of it. - // This is necessary because the app code may interact with the ContentDialog and cause it to - // change states. If we didn't create a new promise, then the very next line of code that runs - // after calling into app code may not be valid because the state may have exited. Starting a - // new promise after each call into app code prevents us from having to worry about this - // problem. In this configuration, when a promise's success handler runs, it guarantees that - // the state hasn't exited. - // For similar reasons, each of the promise chains created in "enter" starts off with a _Signal - // which is completed at the end of the "enter" function (this boilerplate is abstracted away by - // the "interruptible" function). The reason is that we don't want any of the code in "enter" - // to run until the promise chain has been stored in a variable. If we didn't do this (e.g. instead, - // started the promise chain with Promise.wrap()), then the "enter" code could trigger the "exit" - // function (via app code) before the promise chain had been stored in a variable. Under these - // circumstances, the promise chain would be uncancelable and so the "enter" work would be - // unskippable. This wouldn't be good when we needed the state to exit early. - - // These two functions manage interruptible work promises (one creates them the other cancels - // them). They communicate with each other thru the _interruptibleWorkPromises property which - // "interruptible" creates on your object. - - function interruptible(object, workFn) { - object._interruptibleWorkPromises = object._interruptibleWorkPromises || []; - var workStoredSignal = new _Signal(); - object._interruptibleWorkPromises.push(workFn(object, workStoredSignal.promise)); - workStoredSignal.complete(); - } - - function cancelInterruptibles() { - /*jshint validthis: true */ - (this._interruptibleWorkPromises || []).forEach(function (workPromise) { - workPromise.cancel(); - }); - } - - // Transitions: - // When created, the control will take the following initialization transition: - // Init -> Hidden - // Following that, the life of the dialog will be dominated by the following 3 - // sequences of transitions. In geneneral, these sequences are uninterruptible. - // Hidden -> BeforeShow -> Hidden (when preventDefault is called on beforeshow event) - // Hidden -> BeforeShow -> Showing -> Shown - // Shown -> BeforeHide -> Hiding -> Hidden - // Shown -> BeforeHide -> Shown (when preventDefault is called on beforehide event) - // However, any state can be interrupted to go to the Disposed state: - // * -> Disposed - // - // interface IContentDialogState { - // // Debugging - // name: string; - // // State lifecycle - // enter(arg0); - // exit(); - // // ContentDialog's public API surface - // hidden: boolean; - // show(); - // hide(dismissalResult); - // // Events - // onCommandClicked(dismissalResult); - // onInputPaneShown(eventObject); - // onInputPaneHidden(); - // // Provided by _setState for use within the state - // dialog: WinJS.UI.ContentDialog; - // } - - var States = { - // Initial state. Initializes state on the dialog shared by the various states. - Init: _Base.Class.define(null, { - name: "Init", - hidden: true, - enter: function ContentDialog_InitState_enter() { - var dialog = this.dialog; - dialog._dismissable = new _LightDismissService.ModalElement({ - element: dialog._dom.root, - tabIndex: dialog._dom.root.hasAttribute("tabIndex") ? dialog._dom.root.tabIndex : -1, - onLightDismiss: function () { - dialog.hide(DismissalResult.none); - }, - onTakeFocus: function (useSetActive) { - dialog._dismissable.restoreFocus() || - _ElementUtilities._focusFirstFocusableElement(dialog._dom.content) || - _ElementUtilities._tryFocusOnAnyElement(dialog._dom.dialog, useSetActive); - } - }); - this.dialog._dismissedSignal = null; // The signal will be created on demand when show() is called - this.dialog._setState(States.Hidden, false); - }, - exit: _, - show: function ContentDialog_InitState_show() { - throw "It's illegal to call show on the Init state"; - }, - hide: _, - onCommandClicked: _, - onInputPaneShown: _, - onInputPaneHidden: _ - }), - // A rest state. The dialog is hidden and is waiting for the app to call show. - Hidden: _Base.Class.define(null, { - name: "Hidden", - hidden: true, - enter: function ContentDialog_HiddenState_enter(showIsPending) { - if (showIsPending) { - this.show(); - } - }, - exit: _, - show: function ContentDialog_HiddenState_show() { - var dismissedSignal = this.dialog._dismissedSignal = new _Signal(); // save the signal in case it changes when switching states - this.dialog._setState(States.BeforeShow); - return dismissedSignal.promise; - }, - hide: _, - onCommandClicked: _, - onInputPaneShown: _, - onInputPaneHidden: _ - }), - // An event state. The dialog fires the beforeshow event. - BeforeShow: _Base.Class.define(null, { - name: "BeforeShow", - hidden: true, - enter: function ContentDialog_BeforeShowState_enter() { - interruptible(this, function (that, ready) { - return ready.then(function () { - return that.dialog._fireBeforeShow(); // Give opportunity for chain to be canceled when calling into app code - }).then(function (shouldShow) { - if (!shouldShow) { - that.dialog._cancelDismissalPromise(null); // Give opportunity for chain to be canceled when calling into app code - } - return shouldShow; - }).then(function (shouldShow) { - if (shouldShow) { - that.dialog._setState(States.Showing); - } else { - that.dialog._setState(States.Hidden, false); - } - }); - }); - }, - exit: cancelInterruptibles, - show: function ContentDialog_BeforeShowState_show() { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ContentDialogAlreadyShowing", Strings.contentDialogAlreadyShowing)); - }, - hide: _, - onCommandClicked: _, - onInputPaneShown: _, - onInputPaneHidden: _ - }), - // An animation/event state. The dialog plays its entrance animation and fires aftershow. - Showing: _Base.Class.define(null, { - name: "Showing", - hidden: { - get: function ContentDialog_ShowingState_hidden_get() { - return !!this._pendingHide; - } - }, - enter: function ContentDialog_ShowingState_enter() { - interruptible(this, function (that, ready) { - return ready.then(function () { - that._pendingHide = null; - _ElementUtilities.addClass(that.dialog._dom.root, ClassNames._visible); - that.dialog._addExternalListeners(); - if (_WinRT.Windows.UI.ViewManagement.InputPane) { - var inputPaneHeight = _WinRT.Windows.UI.ViewManagement.InputPane.getForCurrentView().occludedRect.height; - if (inputPaneHeight > 0) { - that.dialog._renderForInputPane(inputPaneHeight); - } - } - _LightDismissService.shown(that.dialog._dismissable); - return that.dialog._playEntranceAnimation(); - }).then(function () { - that.dialog._fireEvent(EventNames.afterShow); // Give opportunity for chain to be canceled when calling into app code - }).then(function () { - that.dialog._setState(States.Shown, that._pendingHide); - }); - }); - }, - exit: cancelInterruptibles, - show: function ContentDialog_ShowingState_show() { - if (this._pendingHide) { - var dismissalResult = this._pendingHide.dismissalResult; - this._pendingHide = null; - return this.dialog._resetDismissalPromise(dismissalResult, new _Signal()).promise; - } else { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ContentDialogAlreadyShowing", Strings.contentDialogAlreadyShowing)); - } - }, - hide: function ContentDialog_ShowingState_hide(dismissalResult) { - this._pendingHide = { dismissalResult: dismissalResult }; - }, - onCommandClicked: _, - onInputPaneShown: onInputPaneShown, - onInputPaneHidden: onInputPaneHidden - }), - // A rest state. The dialog is shown and is waiting for the user or the app to trigger hide. - Shown: _Base.Class.define(null, { - name: "Shown", - hidden: false, - enter: function ContentDialog_ShownState_enter(pendingHide) { - if (pendingHide) { - this.hide(pendingHide.dismissalResult); - } - }, - exit: _, - show: function ContentDialog_ShownState_show() { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ContentDialogAlreadyShowing", Strings.contentDialogAlreadyShowing)); - }, - hide: function ContentDialog_ShownState_hide(dismissalResult) { - this.dialog._setState(States.BeforeHide, dismissalResult); - }, - onCommandClicked: function ContentDialog_ShownState_onCommandClicked(dismissalResult) { - this.hide(dismissalResult); - }, - onInputPaneShown: onInputPaneShown, - onInputPaneHidden: onInputPaneHidden - }), - // An event state. The dialog fires the beforehide event. - BeforeHide: _Base.Class.define(null, { - name: "BeforeHide", - hidden: false, - enter: function ContentDialog_BeforeHideState_enter(dismissalResult) { - interruptible(this, function (that, ready) { - return ready.then(function () { - return that.dialog._fireBeforeHide(dismissalResult); // Give opportunity for chain to be canceled when calling into app code - }).then(function (shouldHide) { - if (shouldHide) { - that.dialog._setState(States.Hiding, dismissalResult); - } else { - that.dialog._setState(States.Shown, null); - } - }); - }); - }, - exit: cancelInterruptibles, - show: function ContentDialog_BeforeHideState_show() { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ContentDialogAlreadyShowing", Strings.contentDialogAlreadyShowing)); - }, - hide: _, - onCommandClicked: _, - onInputPaneShown: onInputPaneShown, - onInputPaneHidden: onInputPaneHidden - }), - // An animation/event state. The dialog plays the exit animation and fires the afterhide event. - Hiding: _Base.Class.define(null, { - name: "Hiding", - hidden: { - get: function ContentDialog_HidingState_hidden_get() { - return !this._showIsPending; - } - }, - enter: function ContentDialog_HidingState_enter(dismissalResult) { - interruptible(this, function (that, ready) { - return ready.then(function () { - that._showIsPending = false; - that.dialog._resetDismissalPromise(dismissalResult, null); // Give opportunity for chain to be canceled when calling into app code - }).then(function () { - return that.dialog._playExitAnimation(); - }).then(function () { - that.dialog._removeExternalListeners(); - _LightDismissService.hidden(that.dialog._dismissable); - _ElementUtilities.removeClass(that.dialog._dom.root, ClassNames._visible); - that.dialog._clearInputPaneRendering(); - that.dialog._fireAfterHide(dismissalResult); // Give opportunity for chain to be canceled when calling into app code - }).then(function () { - that.dialog._setState(States.Hidden, that._showIsPending); - }); - }); - }, - exit: cancelInterruptibles, - show: function ContentDialog_HidingState_show() { - if (this._showIsPending) { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ContentDialogAlreadyShowing", Strings.contentDialogAlreadyShowing)); - } else { - this._showIsPending = true; - this.dialog._dismissedSignal = new _Signal(); - return this.dialog._dismissedSignal.promise; - } - }, - hide: function ContentDialog_HidingState_hide(dismissalResult) { - if (this._showIsPending) { - this._showIsPending = false; - this.dialog._resetDismissalPromise(dismissalResult, null); - } - }, - onCommandClicked: _, - onInputPaneShown: _, - onInputPaneHidden: _ - }), - Disposed: _Base.Class.define(null, { - name: "Disposed", - hidden: true, - enter: function ContentDialog_DisposedState_enter() { - _LightDismissService.hidden(this.dialog._dismissable); - this.dialog._removeExternalListeners(); - if (this.dialog._dismissedSignal) { - this.dialog._dismissedSignal.error(new _ErrorFromName("WinJS.UI.ContentDialog.ControlDisposed", Strings.controlDisposed)); - } - }, - exit: _, - show: function ContentDialog_DisposedState_show() { - return Promise.wrapError(new _ErrorFromName("WinJS.UI.ContentDialog.ControlDisposed", Strings.controlDisposed)); - }, - hide: _, - onCommandClicked: _, - onInputPaneShown: _, - onInputPaneHidden: _ - }), - }; - - var ContentDialog = _Base.Class.define(function ContentDialog_ctor(element, options) { - /// - /// - /// Creates a new ContentDialog control. - /// - /// - /// The DOM element that hosts the ContentDialog control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the beforehide event, - /// add a property named "onbeforehide" to the options object and set its value to the event handler. - /// - /// - /// The new ContentDialog. - /// - /// - - // Check to make sure we weren't duplicated - if (element && element.winControl) { - throw new _ErrorFromName("WinJS.UI.ContentDialog.DuplicateConstruction", Strings.duplicateConstruction); - } - options = options || {}; - - this._onInputPaneShownBound = this._onInputPaneShown.bind(this); - this._onInputPaneHiddenBound = this._onInputPaneHidden.bind(this); - - this._disposed = false; - this._resizedForInputPane = false; - this._currentFocus = null; - - this._initializeDom(element || _Global.document.createElement("div")); - this._setState(States.Init); - - this.title = ""; - this.primaryCommandText = ""; - this.primaryCommandDisabled = false; - this.secondaryCommandText = ""; - this.secondaryCommandDisabled = false; - - _Control.setOptions(this, options); - }, { - /// - element: { - get: function ContentDialog_element_get() { - return this._dom.root; - } - }, - - /// - /// The text displayed as the title of the dialog. - /// - title: { - get: function ContentDialog_title_get() { - return this._title; - }, - set: function ContentDialog_title_set(value) { - value = value || ""; - if (this._title !== value) { - this._title = value; - this._dom.title.textContent = value; - this._dom.title.style.display = value ? "" : "none"; - } - } - }, - - /// - /// The text displayed on the primary command's button. - /// - primaryCommandText: { - get: function ContentDialog_primaryCommandText_get() { - return this._primaryCommandText; - }, - set: function ContentDialog_primaryCommandText_set(value) { - value = value || ""; - if (this._primaryCommandText !== value) { - this._primaryCommandText = value; - this._dom.commands[0].textContent = value; - this._updateCommandsUI(); - } - } - }, - - /// - /// The text displayed on the secondary command's button. - /// - secondaryCommandText: { - get: function ContentDialog_secondaryCommandText_get() { - return this._secondaryCommandText; - }, - set: function ContentDialog_secondaryCommandText_set(value) { - value = value || ""; - if (this._secondaryCommandText !== value) { - this._secondaryCommandText = value; - this._dom.commands[1].textContent = value; - this._updateCommandsUI(); - } - } - }, - - /// - /// Indicates whether the button representing the primary command is currently disabled. - /// - primaryCommandDisabled: { - get: function ContentDialog_primaryCommandDisabled_get() { - return this._primaryCommandDisabled; - }, - set: function ContentDialog_primaryCommandDisabled_set(value) { - value = !!value; - if (this._primaryCommandDisabled !== value) { - this._primaryCommandDisabled = value; - this._dom.commands[0].disabled = value; - } - } - }, - - /// - /// Indicates whether the button representing the secondary command is currently disabled. - /// - secondaryCommandDisabled: { - get: function ContentDialog_secondaryCommandDisabled_get() { - return this._secondaryCommandDisabled; - }, - set: function ContentDialog_secondaryCommandDisabled_set(value) { - value = !!value; - if (this._secondaryCommandDisabled !== value) { - this._secondaryCommandDisabled = value; - this._dom.commands[1].disabled = value; - } - } - }, - - /// - hidden: { - get: function ContentDialog_hidden_get() { - return this._state.hidden; - }, - set: function ContentDialog_hidden_set(hidden) { - if (!hidden && this._state.hidden) { - var nop = function () { - }; - // Show returns a promise. If hidden is set while the ContentDialog is disposed, show will return a promise - // error which will be impossible to handle and it'll cause the app to terminate. We'll eat the promise returned by show - // to stop that from happening. - this.show().done(nop, nop); - } else if (hidden && !this._state.hidden) { - this.hide(DismissalResult.none); - } - } - }, - - dispose: function ContentDialog_dispose() { - /// - /// - /// Disposes this control. - /// - /// - if (this._disposed) { - return; - } - this._setState(States.Disposed); - this._disposed = true; - _Dispose._disposeElement(this._dom.content); - }, - - show: function ContentDialog_show() { - /// - /// - /// Shows the ContentDialog. Only one ContentDialog may be shown at a time. If another - /// ContentDialog is already shown, this ContentDialog will remain hidden. - /// - /// - /// A promise which is successfully fulfilled when the dialog is dismissed. The - /// completion value indicates the dialog's dismissal result. This may - /// be 'primary', 'secondary', 'none', or whatever custom value was passed to hide. - /// If this ContentDialog cannot be shown because a ContentDialog is already showing - /// or the ContentDialog is disposed, then the return value is a promise which is in - /// an error state. If preventDefault() is called on the beforeshow event, then this - /// promise will be canceled. - /// - /// - return this._state.show(); - }, - - hide: function ContentDialog_hide(result) { - /// - /// - /// Hides the ContentDialog. - /// - /// - /// A value indicating why the dialog is being hidden. The promise returned - /// by show will be fulfilled with this value. - /// - /// - this._state.hide(result === undefined ? DismissalResult.none : result); - }, - - _initializeDom: function ContentDialog_initializeDom(root) { - // Reparent the children of the root element into the content element. - var contentEl = _Global.document.createElement("div"); - contentEl.className = ClassNames.content; - _ElementUtilities._reparentChildren(root, contentEl); - - root.winControl = this; - _ElementUtilities.addClass(root, ClassNames.contentDialog); - _ElementUtilities.addClass(root, ClassNames._verticalAlignment); - _ElementUtilities.addClass(root, "win-disposable"); - root.innerHTML = - '
' + - '
' + - '' + - '
' + - '
'; - - var dom = {}; - dom.root = root; - dom.backgroundOverlay = dom.root.firstElementChild; - dom.startBodyTab = dom.backgroundOverlay.nextElementSibling; - dom.dialog = dom.startBodyTab.nextElementSibling; - dom.title = dom.dialog.firstElementChild; - dom.scroller = dom.title.nextElementSibling; - dom.commandContainer = dom.scroller.nextElementSibling; - dom.commandSpacer = dom.commandContainer.firstElementChild; - dom.commands = []; - dom.commands.push(dom.commandSpacer.nextElementSibling); - dom.commands.push(dom.commands[0].nextElementSibling); - dom.endBodyTab = dom.dialog.nextElementSibling; - dom.content = contentEl; - this._dom = dom; - - // Put the developer's content into the scroller - dom.scroller.appendChild(dom.content); - - _ElementUtilities._ensureId(dom.title); - _ElementUtilities._ensureId(dom.startBodyTab); - _ElementUtilities._ensureId(dom.endBodyTab); - dom.dialog.setAttribute("aria-labelledby", dom.title.id); - dom.startBodyTab.setAttribute("x-ms-aria-flowfrom", dom.endBodyTab.id); - dom.endBodyTab.setAttribute("aria-flowto", dom.startBodyTab.id); - this._updateTabIndices(); - - dom.root.addEventListener("keydown", this._onKeyDownEnteringElement.bind(this), true); - _ElementUtilities._addEventListener(dom.root, "pointerdown", this._onPointerDown.bind(this)); - _ElementUtilities._addEventListener(dom.root, "pointerup", this._onPointerUp.bind(this)); - dom.root.addEventListener("click", this._onClick.bind(this)); - _ElementUtilities._addEventListener(dom.startBodyTab, "focusin", this._onStartBodyTabFocusIn.bind(this)); - _ElementUtilities._addEventListener(dom.endBodyTab, "focusin", this._onEndBodyTabFocusIn.bind(this)); - dom.commands[0].addEventListener("click", this._onCommandClicked.bind(this, DismissalResult.primary)); - dom.commands[1].addEventListener("click", this._onCommandClicked.bind(this, DismissalResult.secondary)); - }, - - _updateCommandsUI: function ContentDialog_updateCommandsUI() { - this._dom.commands[0].style.display = this.primaryCommandText ? "" : "none"; - this._dom.commands[1].style.display = this.secondaryCommandText ? "" : "none"; - - // commandSpacer's purpose is to ensure that when only 1 button is shown, that button takes up half - // the width of the dialog and is right-aligned. It works by: - // - When only one command is shown: - // - Coming before the other command in the DOM (so the other command will look right-aligned) - // - Having the same flex-grow as the other command (so it occupies half of the space) - // - Having visibility: hidden (so it's invisible but it takes up space) - // - When both commands are shown: - // - Having display: none (so it doesn't occupy any space and the two shown commands each take up half the dialog) - // - When 0 commands are shown: - // - Having display: none (so the commands area takes up no space) - this._dom.commandSpacer.style.display = this.primaryCommandText && !this.secondaryCommandText || !this.primaryCommandText && this.secondaryCommandText ? "" : "none"; - }, - - // _updateTabIndices and _updateTabIndicesImpl are used in tests - _updateTabIndices: function ContentDialog_updateTabIndices() { - if (!this._updateTabIndicesThrottled) { - this._updateTabIndicesThrottled = _BaseUtils._throttledFunction(100, this._updateTabIndicesImpl.bind(this)); - } - this._updateTabIndicesThrottled(); - }, - _updateTabIndicesImpl: function ContentDialog_updateTabIndicesImpl() { - var tabIndex = _ElementUtilities._getHighAndLowTabIndices(this._dom.content); - this._dom.startBodyTab.tabIndex = tabIndex.lowest; - this._dom.commands[0].tabIndex = tabIndex.highest; - this._dom.commands[1].tabIndex = tabIndex.highest; - this._dom.endBodyTab.tabIndex = tabIndex.highest; - }, - - _elementInDialog: function ContentDialog_elementInDialog(element) { - return this._dom.dialog.contains(element) || element === this._dom.startBodyTab || element === this._dom.endBodyTab; - }, - - _onCommandClicked: function ContentDialog_onCommandClicked(dismissalResult) { - this._state.onCommandClicked(dismissalResult); - }, - - _onPointerDown: function ContentDialog_onPointerDown(eventObject) { - eventObject.stopPropagation(); - if (!this._elementInDialog(eventObject.target)) { - eventObject.preventDefault(); - } - }, - - _onPointerUp: function ContentDialog_onPointerUp(eventObject) { - eventObject.stopPropagation(); - if (!this._elementInDialog(eventObject.target)) { - eventObject.preventDefault(); - } - }, - - _onClick: function ContentDialog_onClick(eventObject) { - eventObject.stopPropagation(); - if (!this._elementInDialog(eventObject.target)) { - eventObject.preventDefault(); - } - }, - - _onKeyDownEnteringElement: function ContentDialog_onKeyDownEnteringElement(eventObject) { - if (eventObject.keyCode === _ElementUtilities.Key.tab) { - this._updateTabIndices(); - } - }, - - _onStartBodyTabFocusIn: function ContentDialog_onStartBodyTabFocusIn() { - _ElementUtilities._focusLastFocusableElement(this._dom.dialog); - }, - - _onEndBodyTabFocusIn: function ContentDialog_onEndBodyTabFocusIn() { - _ElementUtilities._focusFirstFocusableElement(this._dom.dialog); - }, - - _onInputPaneShown: function ContentDialog_onInputPaneShown(eventObject) { - this._state.onInputPaneShown(eventObject.detail.originalEvent); - }, - - _onInputPaneHidden: function ContentDialog_onInputPaneHidden() { - this._state.onInputPaneHidden(); - }, - - // - // Methods called by states - // - - _setState: function ContentDialog_setState(NewState, arg0) { - if (!this._disposed) { - this._state && this._state.exit(); - this._state = new NewState(); - this._state.dialog = this; - this._state.enter(arg0); - } - }, - - // Calls into arbitrary app code - _resetDismissalPromise: function ContentDialog_resetDismissalPromise(dismissalResult, newSignal) { - var dismissedSignal = this._dismissedSignal; - var newDismissedSignal = this._dismissedSignal = newSignal; - dismissedSignal.complete({ result: dismissalResult }); - return newDismissedSignal; - }, - - // Calls into arbitrary app code - _cancelDismissalPromise: function ContentDialog_cancelDismissalPromise(newSignal) { - var dismissedSignal = this._dismissedSignal; - var newDismissedSignal = this._dismissedSignal = newSignal; - dismissedSignal.cancel(); - return newDismissedSignal; - }, - - // Calls into arbitrary app code - _fireEvent: function ContentDialog_fireEvent(eventName, options) { - options = options || {}; - var detail = options.detail || null; - var cancelable = !!options.cancelable; - - var eventObject = _Global.document.createEvent("CustomEvent"); - eventObject.initCustomEvent(eventName, true, cancelable, detail); - return this._dom.root.dispatchEvent(eventObject); - }, - - // Calls into arbitrary app code - _fireBeforeShow: function ContentDialog_fireBeforeShow() { - return this._fireEvent(EventNames.beforeShow, { - cancelable: true - }); - }, - - // Calls into arbitrary app code - _fireBeforeHide: function ContentDialog_fireBeforeHide(dismissalResult) { - return this._fireEvent(EventNames.beforeHide, { - detail: { result: dismissalResult }, - cancelable: true - }); - }, - - // Calls into arbitrary app code - _fireAfterHide: function ContentDialog_fireAfterHide(dismissalResult) { - this._fireEvent(EventNames.afterHide, { - detail: { result: dismissalResult } - }); - }, - - _playEntranceAnimation: function ContentDialog_playEntranceAnimation() { - return cancelablePromise(_Animations.fadeIn(this._dom.root)); - }, - - _playExitAnimation: function ContentDialog_playExitAnimation() { - return cancelablePromise(_Animations.fadeOut(this._dom.root)); - }, - - _addExternalListeners: function ContentDialog_addExternalListeners() { - _ElementUtilities._inputPaneListener.addEventListener(this._dom.root, "showing", this._onInputPaneShownBound); - _ElementUtilities._inputPaneListener.addEventListener(this._dom.root, "hiding", this._onInputPaneShownBound); - }, - - _removeExternalListeners: function ContentDialog_removeExternalListeners() { - _ElementUtilities._inputPaneListener.removeEventListener(this._dom.root, "showing", this._onInputPaneShownBound); - _ElementUtilities._inputPaneListener.removeEventListener(this._dom.root, "hiding", this._onInputPaneShownBound); - }, - - _renderForInputPane: function ContentDialog_renderForInputPane(inputPaneHeight) { - this._clearInputPaneRendering(); - - var dialog = this._dom.dialog; - var style = dialog.style; - var left = dialog.offsetLeft; - var top = dialog.offsetTop; - var height = dialog.offsetHeight; - var bottom = top + height; - var visibleBottom = this._dom.root.offsetHeight - inputPaneHeight; - var titleHeight = _ElementUtilities.getTotalHeight(this._dom.title); - var commandsHeight = _ElementUtilities.getTotalHeight(this._dom.commandContainer); - - if (bottom > visibleBottom) { - var newHeight = height - (bottom - visibleBottom); - if (newHeight - titleHeight - commandsHeight < minContentHeightWithInputPane) { - // Put title into scroller so there's more screen real estate for the content - this._dom.scroller.insertBefore(this._dom.title, this._dom.content); - } - - this._dom.root.style.display = "block"; - style.height = newHeight + "px"; - style.position = "absolute"; - style.left = left + "px"; - style.top = top + "px"; - style.minHeight = 0; - - this._resizedForInputPane = true; - _Global.document.activeElement.focus(); // Ensure activeElement is scrolled into view - } - }, - - _clearInputPaneRendering: function ContentDialog_clearInputPaneRendering() { - if (this._resizedForInputPane) { - if (this._dom.title.parentNode !== this._dom.dialog) { - // Make sure the title isn't in the scroller - this._dom.dialog.insertBefore(this._dom.title, this._dom.scroller); - } - - var style = this._dom.dialog.style; - this._dom.root.style.display = ""; - style.height = ""; - style.position = ""; - style.left = ""; - style.top = ""; - style.minHeight = ""; - this._resizedForInputPane = false; - } - } - }, { - /// - /// Specifies the result of dismissing the ContentDialog. - /// - DismissalResult: DismissalResult, - - _ClassNames: ClassNames - }); - _Base.Class.mix(ContentDialog, _Events.createEventProperties( - "beforeshow", - "aftershow", - "beforehide", - "afterhide" - )); - _Base.Class.mix(ContentDialog, _Control.DOMEventMixin); - return ContentDialog; - }) - }); -}); - - -define('require-style!less/styles-splitview',[],function(){}); - -define('require-style!less/colors-splitview',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/SplitView/_SplitView',["require", "exports", '../../Animations', '../../Core/_Base', '../../Core/_BaseUtils', '../../Utilities/_Control', '../../Utilities/_Dispose', '../../Utilities/_ElementUtilities', '../../Core/_ErrorFromName', '../../Core/_Events', '../../Core/_Global', '../../_LightDismissService', '../../Utilities/_OpenCloseMachine'], function (require, exports, Animations, _Base, _BaseUtils, _Control, _Dispose, _ElementUtilities, _ErrorFromName, _Events, _Global, _LightDismissService, _OpenCloseMachine) { - require(["require-style!less/styles-splitview"]); - require(["require-style!less/colors-splitview"]); - "use strict"; - var transformNames = _BaseUtils._browserStyleEquivalents["transform"]; - var Strings = { - get duplicateConstruction() { - return "Invalid argument: Controls may only be instantiated one time for each DOM element"; - } - }; - var ClassNames = { - splitView: "win-splitview", - pane: "win-splitview-pane", - content: "win-splitview-content", - // closed/opened - paneClosed: "win-splitview-pane-closed", - paneOpened: "win-splitview-pane-opened", - _panePlaceholder: "win-splitview-paneplaceholder", - _paneWrapper: "win-splitview-panewrapper", - _contentWrapper: "win-splitview-contentwrapper", - // placement - _placementLeft: "win-splitview-placementleft", - _placementRight: "win-splitview-placementright", - _placementTop: "win-splitview-placementtop", - _placementBottom: "win-splitview-placementbottom", - // closed display mode - _closedDisplayNone: "win-splitview-closeddisplaynone", - _closedDisplayInline: "win-splitview-closeddisplayinline", - // opened display mode - _openedDisplayInline: "win-splitview-openeddisplayinline", - _openedDisplayOverlay: "win-splitview-openeddisplayoverlay" - }; - var EventNames = { - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose" - }; - var Dimension = { - width: "width", - height: "height" - }; - var ClosedDisplayMode = { - /// - /// When the pane is closed, it is not visible and doesn't take up any space. - /// - none: "none", - /// - /// When the pane is closed, it occupies space leaving less room for the SplitView's content. - /// - inline: "inline" - }; - var OpenedDisplayMode = { - /// - /// When the pane is open, it occupies space leaving less room for the SplitView's content. - /// - inline: "inline", - /// - /// When the pane is open, it doesn't take up any space and it is light dismissable. - /// - overlay: "overlay" - }; - var PanePlacement = { - /// - /// Pane is positioned left of the SplitView's content. - /// - left: "left", - /// - /// Pane is positioned right of the SplitView's content. - /// - right: "right", - /// - /// Pane is positioned above the SplitView's content. - /// - top: "top", - /// - /// Pane is positioned below the SplitView's content. - /// - bottom: "bottom" - }; - var closedDisplayModeClassMap = {}; - closedDisplayModeClassMap[ClosedDisplayMode.none] = ClassNames._closedDisplayNone; - closedDisplayModeClassMap[ClosedDisplayMode.inline] = ClassNames._closedDisplayInline; - var openedDisplayModeClassMap = {}; - openedDisplayModeClassMap[OpenedDisplayMode.overlay] = ClassNames._openedDisplayOverlay; - openedDisplayModeClassMap[OpenedDisplayMode.inline] = ClassNames._openedDisplayInline; - var panePlacementClassMap = {}; - panePlacementClassMap[PanePlacement.left] = ClassNames._placementLeft; - panePlacementClassMap[PanePlacement.right] = ClassNames._placementRight; - panePlacementClassMap[PanePlacement.top] = ClassNames._placementTop; - panePlacementClassMap[PanePlacement.bottom] = ClassNames._placementBottom; - // Versions of add/removeClass that are no ops when called with falsy class names. - function addClass(element, className) { - className && _ElementUtilities.addClass(element, className); - } - function removeClass(element, className) { - className && _ElementUtilities.removeClass(element, className); - } - function rectToThickness(rect, dimension) { - return (dimension === Dimension.width) ? { - content: rect.contentWidth, - total: rect.totalWidth - } : { - content: rect.contentHeight, - total: rect.totalHeight - }; - } - /// - /// - /// Displays a SplitView which renders a collapsable pane next to arbitrary HTML content. - /// - /// - /// - /// - /// ]]> - /// Raised just before opening the pane. Call preventDefault on this event to stop the pane from opening. - /// Raised immediately after the pane is fully opened. - /// Raised just before closing the pane. Call preventDefault on this event to stop the pane from closing. - /// Raised immediately after the pane is fully closed. - /// The entire SplitView control. - /// The element which hosts the SplitView's pane. - /// The element which hosts the SplitView's content. - /// - /// - var SplitView = (function () { - function SplitView(element, options) { - /// - /// - /// Creates a new SplitView control. - /// - /// - /// The DOM element that hosts the SplitView control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the beforeclose event, - /// add a property named "onbeforeclose" to the options object and set its value to the event handler. - /// - /// - /// The new SplitView. - /// - /// - var _this = this; - if (options === void 0) { options = {}; } - // State private to _updateDomImpl. No other method should make use of it. - // - // Nothing has been rendered yet so these are all initialized to undefined. Because - // they are undefined, the first time _updateDomImpl is called, they will all be - // rendered. - this._updateDomImpl_rendered = { - paneIsFirst: undefined, - isOpenedMode: undefined, - closedDisplayMode: undefined, - openedDisplayMode: undefined, - panePlacement: undefined, - panePlaceholderWidth: undefined, - panePlaceholderHeight: undefined, - isOverlayShown: undefined - }; - // Check to make sure we weren't duplicated - if (element && element["winControl"]) { - throw new _ErrorFromName("WinJS.UI.SplitView.DuplicateConstruction", Strings.duplicateConstruction); - } - this._initializeDom(element || _Global.document.createElement("div")); - this._machine = new _OpenCloseMachine.OpenCloseMachine({ - eventElement: this._dom.root, - onOpen: function () { - _this._cachedHiddenPaneThickness = null; - var hiddenPaneThickness = _this._getHiddenPaneThickness(); - _this._isOpenedMode = true; - _this._updateDomImpl(); - return _this._playShowAnimation(hiddenPaneThickness); - }, - onClose: function () { - return _this._playHideAnimation(_this._getHiddenPaneThickness()).then(function () { - _this._isOpenedMode = false; - _this._updateDomImpl(); - }); - }, - onUpdateDom: function () { - _this._updateDomImpl(); - }, - onUpdateDomWithIsOpened: function (isOpened) { - _this._isOpenedMode = isOpened; - _this._updateDomImpl(); - } - }); - // Initialize private state. - this._disposed = false; - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._dom.paneWrapper, - tabIndex: -1, - onLightDismiss: function () { - _this.closePane(); - }, - onTakeFocus: function (useSetActive) { - _this._dismissable.restoreFocus() || _ElementUtilities._tryFocusOnAnyElement(_this._dom.pane, useSetActive); - } - }); - this._cachedHiddenPaneThickness = null; - // Initialize public properties. - this.paneOpened = false; - this.closedDisplayMode = ClosedDisplayMode.inline; - this.openedDisplayMode = OpenedDisplayMode.overlay; - this.panePlacement = PanePlacement.left; - _Control.setOptions(this, options); - // Exit the Init state. - _ElementUtilities._inDom(this._dom.root).then(function () { - _this._rtl = _Global.getComputedStyle(_this._dom.root).direction === 'rtl'; - _this._machine.exitInit(); - }); - } - Object.defineProperty(SplitView.prototype, "element", { - /// - get: function () { - return this._dom.root; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "paneElement", { - /// - get: function () { - return this._dom.pane; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "contentElement", { - /// - get: function () { - return this._dom.content; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "closedDisplayMode", { - /// - /// Gets or sets the display mode of the SplitView's pane when it is hidden. - /// - get: function () { - return this._closedDisplayMode; - }, - set: function (value) { - if (ClosedDisplayMode[value] && this._closedDisplayMode !== value) { - this._closedDisplayMode = value; - this._cachedHiddenPaneThickness = null; - this._machine.updateDom(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "openedDisplayMode", { - /// - /// Gets or sets the display mode of the SplitView's pane when it is open. - /// - get: function () { - return this._openedDisplayMode; - }, - set: function (value) { - if (OpenedDisplayMode[value] && this._openedDisplayMode !== value) { - this._openedDisplayMode = value; - this._cachedHiddenPaneThickness = null; - this._machine.updateDom(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "panePlacement", { - /// - /// Gets or sets the placement of the SplitView's pane. - /// - get: function () { - return this._panePlacement; - }, - set: function (value) { - if (PanePlacement[value] && this._panePlacement !== value) { - this._panePlacement = value; - this._cachedHiddenPaneThickness = null; - this._machine.updateDom(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitView.prototype, "paneOpened", { - /// - get: function () { - return this._machine.opened; - }, - set: function (value) { - this._machine.opened = value; - }, - enumerable: true, - configurable: true - }); - SplitView.prototype.dispose = function () { - /// - /// - /// Disposes this control. - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - this._machine.dispose(); - _LightDismissService.hidden(this._dismissable); - _Dispose._disposeElement(this._dom.pane); - _Dispose._disposeElement(this._dom.content); - }; - SplitView.prototype.openPane = function () { - /// - /// - /// Opens the SplitView's pane. - /// - /// - this._machine.open(); - }; - SplitView.prototype.closePane = function () { - /// - /// - /// Closes the SplitView's pane. - /// - /// - this._machine.close(); - }; - SplitView.prototype._initializeDom = function (root) { - // The first child is the pane - var paneEl = root.firstElementChild || _Global.document.createElement("div"); - _ElementUtilities.addClass(paneEl, ClassNames.pane); - if (!paneEl.hasAttribute("tabIndex")) { - paneEl.tabIndex = -1; - } - // All other children are members of the content - var contentEl = _Global.document.createElement("div"); - _ElementUtilities.addClass(contentEl, ClassNames.content); - var child = paneEl.nextSibling; - while (child) { - var sibling = child.nextSibling; - contentEl.appendChild(child); - child = sibling; - } - // paneWrapper's purpose is to clip the pane during the pane resize animation - var paneWrapperEl = _Global.document.createElement("div"); - paneWrapperEl.className = ClassNames._paneWrapper; - paneWrapperEl.appendChild(paneEl); - var panePlaceholderEl = _Global.document.createElement("div"); - panePlaceholderEl.className = ClassNames._panePlaceholder; - // contentWrapper is an extra element we need to allow heights to be specified as percentages (e.g. height: 100%) - // for elements within the content area. It works around this Chrome bug: - // Issue 428049: 100% height doesn't work on child of a definite-flex-basis flex item (in vertical flex container) - // https://code.google.com/p/chromium/issues/detail?id=428049 - // The workaround is that putting a position: absolute element (_dom.content) within the flex item (_dom.contentWrapper) - // allows percentage heights to work within the absolutely positioned element (_dom.content). - var contentWrapperEl = _Global.document.createElement("div"); - contentWrapperEl.className = ClassNames._contentWrapper; - contentWrapperEl.appendChild(contentEl); - root["winControl"] = this; - _ElementUtilities.addClass(root, ClassNames.splitView); - _ElementUtilities.addClass(root, "win-disposable"); - this._dom = { - root: root, - pane: paneEl, - paneWrapper: paneWrapperEl, - panePlaceholder: panePlaceholderEl, - content: contentEl, - contentWrapper: contentWrapperEl - }; - }; - SplitView.prototype._measureElement = function (element) { - var style = getComputedStyle(element); - var position = _ElementUtilities._getPositionRelativeTo(element, this._dom.root); - var marginLeft = parseInt(style.marginLeft, 10); - var marginTop = parseInt(style.marginTop, 10); - return { - left: position.left - marginLeft, - top: position.top - marginTop, - contentWidth: _ElementUtilities.getContentWidth(element), - contentHeight: _ElementUtilities.getContentHeight(element), - totalWidth: _ElementUtilities.getTotalWidth(element), - totalHeight: _ElementUtilities.getTotalHeight(element) - }; - }; - SplitView.prototype._setContentRect = function (contentRect) { - var contentWrapperStyle = this._dom.contentWrapper.style; - contentWrapperStyle.left = contentRect.left + "px"; - contentWrapperStyle.top = contentRect.top + "px"; - contentWrapperStyle.height = contentRect.contentHeight + "px"; - contentWrapperStyle.width = contentRect.contentWidth + "px"; - }; - // Overridden by tests. - SplitView.prototype._prepareAnimation = function (paneRect, contentRect) { - var paneWrapperStyle = this._dom.paneWrapper.style; - paneWrapperStyle.position = "absolute"; - paneWrapperStyle.left = paneRect.left + "px"; - paneWrapperStyle.top = paneRect.top + "px"; - paneWrapperStyle.height = paneRect.totalHeight + "px"; - paneWrapperStyle.width = paneRect.totalWidth + "px"; - var contentWrapperStyle = this._dom.contentWrapper.style; - contentWrapperStyle.position = "absolute"; - this._setContentRect(contentRect); - }; - // Overridden by tests. - SplitView.prototype._clearAnimation = function () { - var paneWrapperStyle = this._dom.paneWrapper.style; - paneWrapperStyle.position = ""; - paneWrapperStyle.left = ""; - paneWrapperStyle.top = ""; - paneWrapperStyle.height = ""; - paneWrapperStyle.width = ""; - paneWrapperStyle[transformNames.scriptName] = ""; - var contentWrapperStyle = this._dom.contentWrapper.style; - contentWrapperStyle.position = ""; - contentWrapperStyle.left = ""; - contentWrapperStyle.top = ""; - contentWrapperStyle.height = ""; - contentWrapperStyle.width = ""; - contentWrapperStyle[transformNames.scriptName] = ""; - var paneStyle = this._dom.pane.style; - paneStyle.height = ""; - paneStyle.width = ""; - paneStyle[transformNames.scriptName] = ""; - }; - SplitView.prototype._getHiddenContentRect = function (shownContentRect, hiddenPaneThickness, shownPaneThickness) { - if (this.openedDisplayMode === OpenedDisplayMode.overlay) { - return shownContentRect; - } - else { - var placementRight = this._rtl ? PanePlacement.left : PanePlacement.right; - var multiplier = this.panePlacement === placementRight || this.panePlacement === PanePlacement.bottom ? 0 : 1; - var paneDiff = { - content: shownPaneThickness.content - hiddenPaneThickness.content, - total: shownPaneThickness.total - hiddenPaneThickness.total - }; - return this._horizontal ? { - left: shownContentRect.left - multiplier * paneDiff.total, - top: shownContentRect.top, - contentWidth: shownContentRect.contentWidth + paneDiff.content, - contentHeight: shownContentRect.contentHeight, - totalWidth: shownContentRect.totalWidth + paneDiff.total, - totalHeight: shownContentRect.totalHeight - } : { - left: shownContentRect.left, - top: shownContentRect.top - multiplier * paneDiff.total, - contentWidth: shownContentRect.contentWidth, - contentHeight: shownContentRect.contentHeight + paneDiff.content, - totalWidth: shownContentRect.totalWidth, - totalHeight: shownContentRect.totalHeight + paneDiff.total - }; - } - }; - Object.defineProperty(SplitView.prototype, "_horizontal", { - get: function () { - return this.panePlacement === PanePlacement.left || this.panePlacement === PanePlacement.right; - }, - enumerable: true, - configurable: true - }); - SplitView.prototype._getHiddenPaneThickness = function () { - if (this._cachedHiddenPaneThickness === null) { - if (this._closedDisplayMode === ClosedDisplayMode.none) { - this._cachedHiddenPaneThickness = { content: 0, total: 0 }; - } - else { - if (this._isOpenedMode) { - _ElementUtilities.removeClass(this._dom.root, ClassNames.paneOpened); - _ElementUtilities.addClass(this._dom.root, ClassNames.paneClosed); - } - var size = this._measureElement(this._dom.pane); - this._cachedHiddenPaneThickness = rectToThickness(size, this._horizontal ? Dimension.width : Dimension.height); - if (this._isOpenedMode) { - _ElementUtilities.removeClass(this._dom.root, ClassNames.paneClosed); - _ElementUtilities.addClass(this._dom.root, ClassNames.paneOpened); - } - } - } - return this._cachedHiddenPaneThickness; - }; - // Should be called while SplitView is rendered in its opened mode - // Overridden by tests. - SplitView.prototype._playShowAnimation = function (hiddenPaneThickness) { - var _this = this; - var dim = this._horizontal ? Dimension.width : Dimension.height; - var shownPaneRect = this._measureElement(this._dom.pane); - var shownContentRect = this._measureElement(this._dom.content); - var shownPaneThickness = rectToThickness(shownPaneRect, dim); - var hiddenContentRect = this._getHiddenContentRect(shownContentRect, hiddenPaneThickness, shownPaneThickness); - this._prepareAnimation(shownPaneRect, hiddenContentRect); - var playPaneAnimation = function () { - var placementRight = _this._rtl ? PanePlacement.left : PanePlacement.right; - // What percentage of the size change should be skipped? (e.g. let's do the first - // 30% of the size change instantly and then animate the other 70%) - var animationOffsetFactor = 0.3; - var from = hiddenPaneThickness.total + animationOffsetFactor * (shownPaneThickness.total - hiddenPaneThickness.total); - return Animations._resizeTransition(_this._dom.paneWrapper, _this._dom.pane, { - from: from, - to: shownPaneThickness.total, - actualSize: shownPaneThickness.total, - dimension: dim, - anchorTrailingEdge: _this.panePlacement === placementRight || _this.panePlacement === PanePlacement.bottom - }); - }; - var playShowAnimation = function () { - if (_this.openedDisplayMode === OpenedDisplayMode.inline) { - _this._setContentRect(shownContentRect); - } - return playPaneAnimation(); - }; - return playShowAnimation().then(function () { - _this._clearAnimation(); - }); - }; - // Should be called while SplitView is rendered in its opened mode - // Overridden by tests. - SplitView.prototype._playHideAnimation = function (hiddenPaneThickness) { - var _this = this; - var dim = this._horizontal ? Dimension.width : Dimension.height; - var shownPaneRect = this._measureElement(this._dom.pane); - var shownContentRect = this._measureElement(this._dom.content); - var shownPaneThickness = rectToThickness(shownPaneRect, dim); - var hiddenContentRect = this._getHiddenContentRect(shownContentRect, hiddenPaneThickness, shownPaneThickness); - this._prepareAnimation(shownPaneRect, shownContentRect); - var playPaneAnimation = function () { - var placementRight = _this._rtl ? PanePlacement.left : PanePlacement.right; - // What percentage of the size change should be skipped? (e.g. let's do the first - // 30% of the size change instantly and then animate the other 70%) - var animationOffsetFactor = 0.3; - var from = shownPaneThickness.total - animationOffsetFactor * (shownPaneThickness.total - hiddenPaneThickness.total); - return Animations._resizeTransition(_this._dom.paneWrapper, _this._dom.pane, { - from: from, - to: hiddenPaneThickness.total, - actualSize: shownPaneThickness.total, - dimension: dim, - anchorTrailingEdge: _this.panePlacement === placementRight || _this.panePlacement === PanePlacement.bottom - }); - }; - var playHideAnimation = function () { - if (_this.openedDisplayMode === OpenedDisplayMode.inline) { - _this._setContentRect(hiddenContentRect); - } - return playPaneAnimation(); - }; - return playHideAnimation().then(function () { - _this._clearAnimation(); - }); - }; - SplitView.prototype._updateDomImpl = function () { - var rendered = this._updateDomImpl_rendered; - var paneShouldBeFirst = this.panePlacement === PanePlacement.left || this.panePlacement === PanePlacement.top; - if (paneShouldBeFirst !== rendered.paneIsFirst) { - // TODO: restore focus - if (paneShouldBeFirst) { - this._dom.root.appendChild(this._dom.panePlaceholder); - this._dom.root.appendChild(this._dom.paneWrapper); - this._dom.root.appendChild(this._dom.contentWrapper); - } - else { - this._dom.root.appendChild(this._dom.contentWrapper); - this._dom.root.appendChild(this._dom.paneWrapper); - this._dom.root.appendChild(this._dom.panePlaceholder); - } - } - rendered.paneIsFirst = paneShouldBeFirst; - if (rendered.isOpenedMode !== this._isOpenedMode) { - if (this._isOpenedMode) { - _ElementUtilities.removeClass(this._dom.root, ClassNames.paneClosed); - _ElementUtilities.addClass(this._dom.root, ClassNames.paneOpened); - } - else { - _ElementUtilities.removeClass(this._dom.root, ClassNames.paneOpened); - _ElementUtilities.addClass(this._dom.root, ClassNames.paneClosed); - } - } - rendered.isOpenedMode = this._isOpenedMode; - if (rendered.panePlacement !== this.panePlacement) { - removeClass(this._dom.root, panePlacementClassMap[rendered.panePlacement]); - addClass(this._dom.root, panePlacementClassMap[this.panePlacement]); - rendered.panePlacement = this.panePlacement; - } - if (rendered.closedDisplayMode !== this.closedDisplayMode) { - removeClass(this._dom.root, closedDisplayModeClassMap[rendered.closedDisplayMode]); - addClass(this._dom.root, closedDisplayModeClassMap[this.closedDisplayMode]); - rendered.closedDisplayMode = this.closedDisplayMode; - } - if (rendered.openedDisplayMode !== this.openedDisplayMode) { - removeClass(this._dom.root, openedDisplayModeClassMap[rendered.openedDisplayMode]); - addClass(this._dom.root, openedDisplayModeClassMap[this.openedDisplayMode]); - rendered.openedDisplayMode = this.openedDisplayMode; - } - var isOverlayShown = this._isOpenedMode && this.openedDisplayMode === OpenedDisplayMode.overlay; - // panePlaceholder's purpose is to take up the amount of space occupied by the - // hidden pane while the pane is shown in overlay mode. Without this, the content - // would shift as the pane shows and hides in overlay mode. - var width, height; - if (isOverlayShown) { - var hiddenPaneThickness = this._getHiddenPaneThickness(); - if (this._horizontal) { - width = hiddenPaneThickness.total + "px"; - height = ""; - } - else { - width = ""; - height = hiddenPaneThickness.total + "px"; - } - } - else { - width = ""; - height = ""; - } - if (rendered.panePlaceholderWidth !== width || rendered.panePlaceholderHeight !== height) { - var style = this._dom.panePlaceholder.style; - style.width = width; - style.height = height; - rendered.panePlaceholderWidth = width; - rendered.panePlaceholderHeight = height; - } - if (rendered.isOverlayShown !== isOverlayShown) { - if (isOverlayShown) { - _LightDismissService.shown(this._dismissable); - } - else { - _LightDismissService.hidden(this._dismissable); - } - rendered.isOverlayShown = isOverlayShown; - } - }; - /// - /// Display options for a SplitView's pane when it is closed. - /// - SplitView.ClosedDisplayMode = ClosedDisplayMode; - /// - /// Display options for a SplitView's pane when it is open. - /// - SplitView.OpenedDisplayMode = OpenedDisplayMode; - /// - /// Placement options for a SplitView's pane. - /// - SplitView.PanePlacement = PanePlacement; - SplitView.supportedForProcessing = true; - SplitView._ClassNames = ClassNames; - return SplitView; - })(); - exports.SplitView = SplitView; - _Base.Class.mix(SplitView, _Events.createEventProperties(EventNames.beforeOpen, EventNames.afterOpen, EventNames.beforeClose, EventNames.afterClose)); - _Base.Class.mix(SplitView, _Control.DOMEventMixin); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/SplitView',["require", "exports", '../Core/_Base'], function (require, exports, _Base) { - var module = null; - _Base.Namespace.define("WinJS.UI", { - SplitView: { - get: function () { - if (!module) { - require(["./SplitView/_SplitView"], function (m) { - module = m; - }); - } - return module.SplitView; - } - } - }); -}); - - -define('require-style!less/styles-splitviewpanetoggle',[],function(){}); - -define('require-style!less/colors-splitviewpanetoggle',[],function(){}); -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/SplitViewPaneToggle/_SplitViewPaneToggle',["require", "exports", '../../Core/_Base', '../../Utilities/_Control', '../../Utilities/_ElementUtilities', '../../Core/_ErrorFromName', '../../Core/_Events', '../../Core/_Global', '../../Utilities/_KeyboardBehavior', '../../Utilities/_Hoverable'], function (require, exports, _Base, _Control, _ElementUtilities, _ErrorFromName, _Events, _Global, _KeyboardBehavior, _Hoverable) { - _Hoverable.isHoverable; // Force dependency on the hoverable module - require(["require-style!less/styles-splitviewpanetoggle"]); - require(["require-style!less/colors-splitviewpanetoggle"]); - "use strict"; - // This control has 2 modes depending on whether or not the app has provided a SplitView: - // - SplitView not provided - // SplitViewPaneToggle provides button visuals and fires the invoked event. The app - // intends to do everything else: - // - Handle the invoked event - // - Handle the SplitView opening and closing - // - Handle aria-expanded being mutated by UIA (i.e. screen readers) - // - Keep the aria-controls attribute, aria-expanded attribute, and SplitView in sync - // - SplitView is provided via splitView property - // SplitViewPaneToggle keeps the SplitView, the aria-controls attribute, and the - // aria-expands attribute in sync. In this use case, apps typically won't listen - // to the invoked event (but it's still fired). - var ClassNames = { - splitViewPaneToggle: "win-splitviewpanetoggle" - }; - var EventNames = { - // Fires when the user invokes the button with mouse/keyboard/touch. Does not - // fire if the SplitViewPaneToggle's state changes due to UIA (i.e. aria-expanded - // being set) or due to the SplitView pane opening/closing. - invoked: "invoked" - }; - var Strings = { - get duplicateConstruction() { - return "Invalid argument: Controls may only be instantiated one time for each DOM element"; - }, - get badButtonElement() { - return "Invalid argument: The SplitViewPaneToggle's element must be a button element"; - } - }; - // The splitViewElement may not have a winControl associated with it yet in the case - // that the SplitViewPaneToggle was constructed before the SplitView. This may happen - // when WinJS.UI.processAll is used to construct the controls because the order of construction - // depends on the order in which the SplitView and SplitViewPaneToggle appear in the DOM. - function getSplitViewControl(splitViewElement) { - return (splitViewElement && splitViewElement["winControl"]); - } - function getPaneOpened(splitViewElement) { - var splitViewControl = getSplitViewControl(splitViewElement); - return splitViewControl ? splitViewControl.paneOpened : false; - } - /// - /// - /// Displays a button which is used for opening and closing a SplitView's pane. - /// - /// - /// - /// - /// ]]> - /// The SplitViewPaneToggle control itself. - /// - /// - var SplitViewPaneToggle = (function () { - function SplitViewPaneToggle(element, options) { - /// - /// - /// Creates a new SplitViewPaneToggle control. - /// - /// - /// The DOM element that hosts the SplitViewPaneToggle control. - /// - /// - /// An object that contains one or more property/value pairs to apply to the new control. - /// Each property of the options object corresponds to one of the control's properties or events. - /// Event names must begin with "on". For example, to provide a handler for the invoked event, - /// add a property named "oninvoked" to the options object and set its value to the event handler. - /// - /// - /// The new SplitViewPaneToggle. - /// - /// - if (options === void 0) { options = {}; } - // State private to _updateDom. No other method should make use of it. - // - // Nothing has been rendered yet so these are all initialized to undefined. Because - // they are undefined, the first time _updateDom is called, they will all be - // rendered. - this._updateDom_rendered = { - splitView: undefined - }; - // Check to make sure we weren't duplicated - if (element && element["winControl"]) { - throw new _ErrorFromName("WinJS.UI.SplitViewPaneToggle.DuplicateConstruction", Strings.duplicateConstruction); - } - this._onPaneStateSettledBound = this._onPaneStateSettled.bind(this); - this._ariaExpandedMutationObserver = new _ElementUtilities._MutationObserver(this._onAriaExpandedPropertyChanged.bind(this)); - this._initializeDom(element || _Global.document.createElement("button")); - // Private state - this._disposed = false; - // Default values - this.splitView = null; - _Control.setOptions(this, options); - this._initialized = true; - this._updateDom(); - } - Object.defineProperty(SplitViewPaneToggle.prototype, "element", { - /// - get: function () { - return this._dom.root; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(SplitViewPaneToggle.prototype, "splitView", { - /// - get: function () { - return this._splitView; - }, - set: function (splitView) { - this._splitView = splitView; - if (splitView) { - this._opened = getPaneOpened(splitView); - } - this._updateDom(); - }, - enumerable: true, - configurable: true - }); - SplitViewPaneToggle.prototype.dispose = function () { - /// - /// - /// Disposes this control. - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - this._splitView && this._removeListeners(this._splitView); - }; - SplitViewPaneToggle.prototype._initializeDom = function (root) { - if (root.tagName !== "BUTTON") { - throw new _ErrorFromName("WinJS.UI.SplitViewPaneToggle.BadButtonElement", Strings.badButtonElement); - } - root["winControl"] = this; - _ElementUtilities.addClass(root, ClassNames.splitViewPaneToggle); - _ElementUtilities.addClass(root, "win-disposable"); - if (!root.hasAttribute("type")) { - root.type = "button"; - } - new _KeyboardBehavior._WinKeyboard(root); - root.addEventListener("click", this._onClick.bind(this)); - this._dom = { - root: root - }; - }; - SplitViewPaneToggle.prototype._updateDom = function () { - if (!this._initialized || this._disposed) { - return; - } - var rendered = this._updateDom_rendered; - if (this._splitView !== rendered.splitView) { - if (rendered.splitView) { - this._dom.root.removeAttribute("aria-controls"); - this._removeListeners(rendered.splitView); - } - if (this._splitView) { - _ElementUtilities._ensureId(this._splitView); - this._dom.root.setAttribute("aria-controls", this._splitView.id); - this._addListeners(this._splitView); - } - rendered.splitView = this._splitView; - } - // When no SplitView is provided, it's up to the app to manage aria-expanded. - if (this._splitView) { - // Always update aria-expanded and don't cache its most recently rendered value - // in _updateDom_rendered. The reason is that we're not the only ones that update - // aria-expanded. aria-expanded may be changed thru UIA APIs. Consequently, if we - // cached the last value we set in _updateDom_rendered, it may not reflect the current - // value in the DOM. - var expanded = this._opened ? "true" : "false"; - _ElementUtilities._setAttribute(this._dom.root, "aria-expanded", expanded); - // The splitView element may not have a winControl associated with it yet in the case - // that the SplitViewPaneToggle was constructed before the SplitView. This may happen - // when WinJS.UI.processAll is used to construct the controls because the order of construction - // depends on the order in which the SplitView and SplitViewPaneToggle appear in the DOM. - var splitViewControl = getSplitViewControl(this._splitView); - if (splitViewControl) { - splitViewControl.paneOpened = this._opened; - } - } - }; - SplitViewPaneToggle.prototype._addListeners = function (splitViewElement) { - splitViewElement.addEventListener("_openCloseStateSettled", this._onPaneStateSettledBound); - this._ariaExpandedMutationObserver.observe(this._dom.root, { - attributes: true, - attributeFilter: ["aria-expanded"] - }); - }; - SplitViewPaneToggle.prototype._removeListeners = function (splitViewElement) { - splitViewElement.removeEventListener("_openCloseStateSettled", this._onPaneStateSettledBound); - this._ariaExpandedMutationObserver.disconnect(); - }; - SplitViewPaneToggle.prototype._fireEvent = function (eventName) { - var eventObject = _Global.document.createEvent("CustomEvent"); - eventObject.initCustomEvent(eventName, true, false, null); - return this._dom.root.dispatchEvent(eventObject); - }; - // Inputs that change the SplitViewPaneToggle's state - // - SplitViewPaneToggle.prototype._onPaneStateSettled = function (eventObject) { - if (eventObject.target === this._splitView) { - this._opened = getPaneOpened(this._splitView); - this._updateDom(); - } - }; - // Called by tests. - SplitViewPaneToggle.prototype._onAriaExpandedPropertyChanged = function (mutations) { - var ariaExpanded = this._dom.root.getAttribute("aria-expanded") === "true"; - this._opened = ariaExpanded; - this._updateDom(); - }; - SplitViewPaneToggle.prototype._onClick = function (eventObject) { - this._invoked(); - }; - // Called by tests. - SplitViewPaneToggle.prototype._invoked = function () { - if (this._disposed) { - return; - } - if (this._splitView) { - this._opened = !this._opened; - this._updateDom(); - } - this._fireEvent(EventNames.invoked); - }; - SplitViewPaneToggle._ClassNames = ClassNames; - SplitViewPaneToggle.supportedForProcessing = true; - return SplitViewPaneToggle; - })(); - exports.SplitViewPaneToggle = SplitViewPaneToggle; - _Base.Class.mix(SplitViewPaneToggle, _Events.createEventProperties(EventNames.invoked)); - _Base.Class.mix(SplitViewPaneToggle, _Control.DOMEventMixin); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/SplitViewPaneToggle',["require", "exports", '../Core/_Base'], function (require, exports, _Base) { - var module = null; - _Base.Namespace.define("WinJS.UI", { - SplitViewPaneToggle: { - get: function () { - if (!module) { - require(["./SplitViewPaneToggle/_SplitViewPaneToggle"], function (m) { - module = m; - }); - } - return module.SplitViewPaneToggle; - } - } - }); -}); - -define('WinJS/Controls/AppBar/_Constants',["require", "exports", "../CommandingSurface/_Constants"], function (require, exports, _CommandingSurfaceConstants) { - // appbar class names - exports.ClassNames = { - controlCssClass: "win-appbar", - disposableCssClass: "win-disposable", - actionAreaCssClass: "win-appbar-actionarea", - overflowButtonCssClass: "win-appbar-overflowbutton", - spacerCssClass: "win-appbar-spacer", - ellipsisCssClass: "win-appbar-ellipsis", - overflowAreaCssClass: "win-appbar-overflowarea", - contentFlyoutCssClass: "win-appbar-contentflyout", - emptyappbarCssClass: "win-appbar-empty", - menuCssClass: "win-menu", - menuContainsToggleCommandClass: "win-menu-containstogglecommand", - openedClass: "win-appbar-opened", - closedClass: "win-appbar-closed", - noneClass: "win-appbar-closeddisplaynone", - minimalClass: "win-appbar-closeddisplayminimal", - compactClass: "win-appbar-closeddisplaycompact", - fullClass: "win-appbar-closeddisplayfull", - placementTopClass: "win-appbar-top", - placementBottomClass: "win-appbar-bottom", - }; - exports.EventNames = { - // AppBar - beforeOpen: "beforeopen", - afterOpen: "afteropen", - beforeClose: "beforeclose", - afterClose: "afterclose", - // AppBarCommand - commandPropertyMutated: "_commandpropertymutated", - }; - exports.controlMinWidth = _CommandingSurfaceConstants.controlMinWidth; - exports.defaultClosedDisplayMode = "compact"; - exports.defaultOpened = false; - exports.defaultPlacement = "bottom"; - // Constants for commands - exports.typeSeparator = "separator"; - exports.typeContent = "content"; - exports.typeButton = "button"; - exports.typeToggle = "toggle"; - exports.typeFlyout = "flyout"; - exports.commandSelector = ".win-command"; - exports.primaryCommandSection = "primary"; - exports.secondaryCommandSection = "secondary"; -}); - - -define('require-style!less/styles-appbar',[],function(){}); -define('WinJS/Controls/AppBar/_AppBar',["require", "exports", "../../Core/_Base", "../AppBar/_Constants", "../CommandingSurface", "../../Utilities/_Control", "../../Utilities/_Dispose", "../../Utilities/_ElementUtilities", "../../Core/_ErrorFromName", '../../Core/_Events', "../../Core/_Global", '../../Utilities/_KeyboardInfo', '../../_LightDismissService', '../../Promise', "../../Core/_Resources", '../../Utilities/_OpenCloseMachine', "../../Core/_WriteProfilerMark"], function (require, exports, _Base, _Constants, _CommandingSurface, _Control, _Dispose, _ElementUtilities, _ErrorFromName, _Events, _Global, _KeyboardInfo, _LightDismissService, Promise, _Resources, _OpenCloseMachine, _WriteProfilerMark) { - require(["require-style!less/styles-appbar"]); - "use strict"; - var keyboardInfo = _KeyboardInfo._KeyboardInfo; - var strings = { - get ariaLabel() { - return _Resources._getWinJSString("ui/appBarAriaLabel").value; - }, - get overflowButtonAriaLabel() { - return _Resources._getWinJSString("ui/appBarOverflowButtonAriaLabel").value; - }, - get mustContainCommands() { - return "The AppBar can only contain WinJS.UI.Command or WinJS.UI.AppBarCommand controls"; - }, - get duplicateConstruction() { - return "Invalid argument: Controls may only be instantiated one time for each DOM element"; - } - }; - var ClosedDisplayMode = { - /// - /// When the AppBar is closed, it is not visible and doesn't take up any space. - /// - none: "none", - /// - /// When the AppBar is closed, its height is reduced to the minimal height required to display only its overflowbutton. All other content in the AppBar is not displayed. - /// - minimal: "minimal", - /// - /// When the AppBar is closed, its height is reduced such that button commands are still visible, but their labels are hidden. - /// - compact: "compact", - /// - /// When the AppBar is closed, its height is always sized to content. - /// - full: "full", - }; - var closedDisplayModeClassMap = {}; - closedDisplayModeClassMap[ClosedDisplayMode.none] = _Constants.ClassNames.noneClass; - closedDisplayModeClassMap[ClosedDisplayMode.minimal] = _Constants.ClassNames.minimalClass; - closedDisplayModeClassMap[ClosedDisplayMode.compact] = _Constants.ClassNames.compactClass; - closedDisplayModeClassMap[ClosedDisplayMode.full] = _Constants.ClassNames.fullClass; - var Placement = { - /// - /// The AppBar appears at the top of the main view - /// - top: "top", - /// - /// The AppBar appears at the bottom of the main view - /// - bottom: "bottom", - }; - var placementClassMap = {}; - placementClassMap[Placement.top] = _Constants.ClassNames.placementTopClass; - placementClassMap[Placement.bottom] = _Constants.ClassNames.placementBottomClass; - // Versions of add/removeClass that are no ops when called with falsy class names. - function addClass(element, className) { - className && _ElementUtilities.addClass(element, className); - } - function removeClass(element, className) { - className && _ElementUtilities.removeClass(element, className); - } - /// - /// - /// Represents an appbar for displaying commands. - /// - /// - /// - /// - /// - /// - /// ]]> - /// The entire AppBar control. - /// The appbar overflow button. - /// The container for appbar commands that overflow. - /// - /// - var AppBar = (function () { - function AppBar(element, options) { - /// - /// - /// Creates a new AppBar control. - /// - /// - /// The DOM element that will host the control. - /// - /// - /// The set of properties and values to apply to the new AppBar control. - /// - /// - /// The new AppBar control. - /// - /// - var _this = this; - if (options === void 0) { options = {}; } - // State private to the _updateDomImpl family of method. No other methods should make use of it. - // - // Nothing has been rendered yet so these are all initialized to undefined. Because - // they are undefined, the first time _updateDomImpl is called, they will all be - // rendered. - this._updateDomImpl_renderedState = { - isOpenedMode: undefined, - placement: undefined, - closedDisplayMode: undefined, - adjustedOffsets: { top: undefined, bottom: undefined }, - }; - this._writeProfilerMark("constructor,StartTM"); - // Check to make sure we weren't duplicated - if (element && element["winControl"]) { - throw new _ErrorFromName("WinJS.UI.AppBar.DuplicateConstruction", strings.duplicateConstruction); - } - this._initializeDom(element || _Global.document.createElement("div")); - var stateMachine = new _OpenCloseMachine.OpenCloseMachine({ - eventElement: this.element, - onOpen: function () { - var openAnimation = _this._commandingSurface.createOpenAnimation(_this._getClosedHeight()); - // We're temporarily setting the AppBar's style from position=-ms-device-fixed to fixed to work around an animations bug in IE, - // where two AppBars will end up being rendered when animating instead of one. - // We need to recalculate our offsets relative to the top and bottom of the visible document because position fixed elements use layout viewport coordinates - // while position -ms-device-fixed use visual viewport coordinates.This difference in coordinate systems is especially pronounced if the IHM has caused the visual viewport to resize. - _this.element.style.position = "fixed"; - if (_this._placement === AppBar.Placement.top) { - _this.element.style.top = _KeyboardInfo._KeyboardInfo._layoutViewportCoords.visibleDocTop + "px"; - } - else { - _this.element.style.bottom = _KeyboardInfo._KeyboardInfo._layoutViewportCoords.visibleDocBottom + "px"; - } - _this._synchronousOpen(); - return openAnimation.execute().then(function () { - _this.element.style.position = ""; - _this.element.style.top = _this._adjustedOffsets.top; - _this.element.style.bottom = _this._adjustedOffsets.bottom; - }); - }, - onClose: function () { - var closeAnimation = _this._commandingSurface.createCloseAnimation(_this._getClosedHeight()); - // We're temporarily setting the AppBar's style from position=-ms-device-fixed to fixed to work around an animations bug in IE, - // where two AppBars will end up being rendered when animating instead of one. - // We need to recalculate our offsets relative to the top and bottom of the visible document because position fixed elements use layout viewport coordinates - // while position -ms-device-fixed use visual viewport coordinates.This difference in coordinate systems is especially pronounced if the IHM has caused the visual viewport to resize. - _this.element.style.position = "fixed"; - if (_this._placement === AppBar.Placement.top) { - _this.element.style.top = _KeyboardInfo._KeyboardInfo._layoutViewportCoords.visibleDocTop + "px"; - } - else { - _this.element.style.bottom = _KeyboardInfo._KeyboardInfo._layoutViewportCoords.visibleDocBottom + "px"; - } - return closeAnimation.execute().then(function () { - _this._synchronousClose(); - _this.element.style.position = ""; - _this.element.style.top = _this._adjustedOffsets.top; - _this.element.style.bottom = _this._adjustedOffsets.bottom; - }); - }, - onUpdateDom: function () { - _this._updateDomImpl(); - }, - onUpdateDomWithIsOpened: function (isOpened) { - _this._isOpenedMode = isOpened; - _this._updateDomImpl(); - } - }); - // Events - this._handleShowingKeyboardBound = this._handleShowingKeyboard.bind(this); - this._handleHidingKeyboardBound = this._handleHidingKeyboard.bind(this); - _ElementUtilities._inputPaneListener.addEventListener(this._dom.root, "showing", this._handleShowingKeyboardBound); - _ElementUtilities._inputPaneListener.addEventListener(this._dom.root, "hiding", this._handleHidingKeyboardBound); - // Initialize private state. - this._disposed = false; - this._cachedClosedHeight = null; - this._commandingSurface = new _CommandingSurface._CommandingSurface(this._dom.commandingSurfaceEl, { openCloseMachine: stateMachine }); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-actionarea"), _Constants.ClassNames.actionAreaCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-overflowarea"), _Constants.ClassNames.overflowAreaCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-overflowbutton"), _Constants.ClassNames.overflowButtonCssClass); - addClass(this._dom.commandingSurfaceEl.querySelector(".win-commandingsurface-ellipsis"), _Constants.ClassNames.ellipsisCssClass); - this._isOpenedMode = _Constants.defaultOpened; - this._dismissable = new _LightDismissService.LightDismissableElement({ - element: this._dom.root, - tabIndex: this._dom.root.hasAttribute("tabIndex") ? this._dom.root.tabIndex : -1, - onLightDismiss: function () { - _this.close(); - } - }); - // Initialize public properties. - this.closedDisplayMode = _Constants.defaultClosedDisplayMode; - this.placement = _Constants.defaultPlacement; - this.opened = this._isOpenedMode; - _Control.setOptions(this, options); - // Exit the Init state. - _ElementUtilities._inDom(this.element).then(function () { - return _this._commandingSurface.initialized; - }).then(function () { - stateMachine.exitInit(); - _this._writeProfilerMark("constructor,StopTM"); - }); - } - Object.defineProperty(AppBar.prototype, "element", { - /// - get: function () { - return this._dom.root; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AppBar.prototype, "data", { - /// - /// Gets or sets the Binding List of WinJS.UI.Command for the AppBar. - /// - get: function () { - return this._commandingSurface.data; - }, - set: function (value) { - this._commandingSurface.data = value; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AppBar.prototype, "closedDisplayMode", { - /// - /// Gets or sets the closedDisplayMode for the AppBar. Values are "none", "minimal", "compact" and "full". - /// - get: function () { - return this._commandingSurface.closedDisplayMode; - }, - set: function (value) { - if (ClosedDisplayMode[value]) { - this._commandingSurface.closedDisplayMode = value; - this._cachedClosedHeight = null; - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AppBar.prototype, "placement", { - /// - get: function () { - return this._placement; - }, - set: function (value) { - if (Placement[value] && this._placement !== value) { - this._placement = value; - switch (value) { - case Placement.top: - this._commandingSurface.overflowDirection = "bottom"; - break; - case Placement.bottom: - this._commandingSurface.overflowDirection = "top"; - break; - } - this._adjustedOffsets = this._computeAdjustedOffsets(); - this._commandingSurface.deferredDomUpate(); - } - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(AppBar.prototype, "opened", { - /// - get: function () { - return this._commandingSurface.opened; - }, - set: function (value) { - this._commandingSurface.opened = value; - }, - enumerable: true, - configurable: true - }); - AppBar.prototype.open = function () { - /// - /// - /// Opens the AppBar - /// - /// - this._commandingSurface.open(); - }; - AppBar.prototype.close = function () { - /// - /// - /// Closes the AppBar - /// - /// - this._commandingSurface.close(); - }; - AppBar.prototype.dispose = function () { - /// - /// - /// Disposes this AppBar. - /// - /// - if (this._disposed) { - return; - } - this._disposed = true; - _LightDismissService.hidden(this._dismissable); - // Disposing the _commandingSurface will trigger dispose on its OpenCloseMachine - // and synchronously complete any animations that might have been running. - this._commandingSurface.dispose(); - _ElementUtilities._inputPaneListener.removeEventListener(this._dom.root, "showing", this._handleShowingKeyboardBound); - _ElementUtilities._inputPaneListener.removeEventListener(this._dom.root, "hiding", this._handleHidingKeyboardBound); - _Dispose.disposeSubTree(this.element); - }; - AppBar.prototype.forceLayout = function () { - /// - /// - /// Forces the AppBar to update its layout. Use this function when the window did not change size, but the container of the AppBar changed size. - /// - /// - this._commandingSurface.forceLayout(); - }; - AppBar.prototype.getCommandById = function (id) { - /// - /// - /// Retrieves the command with the specified ID from this AppBar. - /// If more than one command is found, this method returns the first command found. - /// - /// Id of the command to return. - /// - /// The command found, or null if no command is found. - /// - /// - return this._commandingSurface.getCommandById(id); - }; - AppBar.prototype.showOnlyCommands = function (commands) { - /// - /// - /// Show the specified commands, hiding all of the others in the AppBar. - /// - /// - /// An array of the commands to show. The array elements may be Command objects, or the string identifiers (IDs) of commands. - /// - /// - return this._commandingSurface.showOnlyCommands(commands); - }; - AppBar.prototype._writeProfilerMark = function (text) { - _WriteProfilerMark("WinJS.UI.AppBar:" + this._id + ":" + text); - }; - AppBar.prototype._initializeDom = function (root) { - this._writeProfilerMark("_intializeDom,info"); - // Attaching JS control to DOM element - root["winControl"] = this; - this._id = root.id || _ElementUtilities._uniqueID(root); - _ElementUtilities.addClass(root, _Constants.ClassNames.controlCssClass); - _ElementUtilities.addClass(root, _Constants.ClassNames.disposableCssClass); - // Make sure we have an ARIA role - var role = root.getAttribute("role"); - if (!role) { - root.setAttribute("role", "menubar"); - } - var label = root.getAttribute("aria-label"); - if (!label) { - root.setAttribute("aria-label", strings.ariaLabel); - } - // Create element for commandingSurface and reparent any declarative Commands. - // commandingSurface will parse child elements as AppBarCommands. - var commandingSurfaceEl = document.createElement("DIV"); - _ElementUtilities._reparentChildren(root, commandingSurfaceEl); - root.appendChild(commandingSurfaceEl); - this._dom = { - root: root, - commandingSurfaceEl: commandingSurfaceEl, - }; - }; - AppBar.prototype._handleShowingKeyboard = function (event) { - // If the IHM resized the window, we can rely on -ms-device-fixed positioning to remain visible. - // If the IHM does not resize the window we will need to adjust our offsets to avoid being occluded - // The IHM does not cause a window resize to happen right away, set a timeout to check if the viewport - // has been resized after enough time has passed for both the IHM animation, and scroll-into-view, to - // complete. - var _this = this; - // If focus is in the AppBar, tell the platform we will move ourselves. - if (this._dom.root.contains(_Global.document.activeElement)) { - var inputPaneEvent = event.detail.originalEvent; - inputPaneEvent.ensuredFocusedElementInView = true; - } - var duration = keyboardInfo._animationShowLength + keyboardInfo._scrollTimeout; - // Returns a promise for unit tests to verify the correct behavior after the timeout. - return Promise.timeout(duration).then(function () { - if (_this._shouldAdjustForShowingKeyboard() && !_this._disposed) { - _this._adjustedOffsets = _this._computeAdjustedOffsets(); - _this._commandingSurface.deferredDomUpate(); - } - }); - }; - AppBar.prototype._shouldAdjustForShowingKeyboard = function () { - // Overwriteable for unit tests - // Determines if an AppBar needs to adjust its position to move in response to a shown IHM, or if it can - // just ride the bottom of the visual viewport to remain visible. The latter requires that the IHM has - // caused the viewport to resize. - return keyboardInfo._visible && !keyboardInfo._isResized; - }; - AppBar.prototype._handleHidingKeyboard = function () { - // Make sure AppBar has the correct offsets since it could have been displaced by the IHM. - this._adjustedOffsets = this._computeAdjustedOffsets(); - this._commandingSurface.deferredDomUpate(); - }; - AppBar.prototype._computeAdjustedOffsets = function () { - // Position the AppBar element relative to the top or bottom edge of the visible - // document. - var offsets = { top: "", bottom: "" }; - if (this._placement === Placement.bottom) { - // If the IHM is open, the bottom of the visual viewport may or may not be occluded - offsets.bottom = keyboardInfo._visibleDocBottomOffset + "px"; - } - else if (this._placement === Placement.top) { - offsets.top = keyboardInfo._visibleDocTop + "px"; - } - return offsets; - }; - AppBar.prototype._synchronousOpen = function () { - this._isOpenedMode = true; - this._updateDomImpl(); - }; - AppBar.prototype._synchronousClose = function () { - this._isOpenedMode = false; - this._updateDomImpl(); - }; - AppBar.prototype._updateDomImpl = function () { - var rendered = this._updateDomImpl_renderedState; - if (rendered.isOpenedMode !== this._isOpenedMode) { - if (this._isOpenedMode) { - this._updateDomImpl_renderOpened(); - } - else { - this._updateDomImpl_renderClosed(); - } - rendered.isOpenedMode = this._isOpenedMode; - } - if (rendered.placement !== this.placement) { - removeClass(this._dom.root, placementClassMap[rendered.placement]); - addClass(this._dom.root, placementClassMap[this.placement]); - rendered.placement = this.placement; - } - if (rendered.closedDisplayMode !== this.closedDisplayMode) { - removeClass(this._dom.root, closedDisplayModeClassMap[rendered.closedDisplayMode]); - addClass(this._dom.root, closedDisplayModeClassMap[this.closedDisplayMode]); - rendered.closedDisplayMode = this.closedDisplayMode; - } - if (rendered.adjustedOffsets.top !== this._adjustedOffsets.top) { - this._dom.root.style.top = this._adjustedOffsets.top; - rendered.adjustedOffsets.top = this._adjustedOffsets.top; - } - if (rendered.adjustedOffsets.bottom !== this._adjustedOffsets.bottom) { - this._dom.root.style.bottom = this._adjustedOffsets.bottom; - rendered.adjustedOffsets.bottom = this._adjustedOffsets.bottom; - } - this._commandingSurface.updateDomImpl(); - }; - AppBar.prototype._getClosedHeight = function () { - if (this._cachedClosedHeight === null) { - var wasOpen = this._isOpenedMode; - if (this._isOpenedMode) { - this._synchronousClose(); - } - this._cachedClosedHeight = this._commandingSurface.getBoundingRects().commandingSurface.height; - if (wasOpen) { - this._synchronousOpen(); - } - } - return this._cachedClosedHeight; - }; - AppBar.prototype._updateDomImpl_renderOpened = function () { - addClass(this._dom.root, _Constants.ClassNames.openedClass); - removeClass(this._dom.root, _Constants.ClassNames.closedClass); - this._commandingSurface.synchronousOpen(); - _LightDismissService.shown(this._dismissable); // Call at the start of the open animation - }; - AppBar.prototype._updateDomImpl_renderClosed = function () { - addClass(this._dom.root, _Constants.ClassNames.closedClass); - removeClass(this._dom.root, _Constants.ClassNames.openedClass); - this._commandingSurface.synchronousClose(); - _LightDismissService.hidden(this._dismissable); // Call after the close animation - }; - /// - /// Display options for the AppBar when closed. - /// - AppBar.ClosedDisplayMode = ClosedDisplayMode; - /// - /// Display options for AppBar placement in relation to the main view. - /// - AppBar.Placement = Placement; - AppBar.supportedForProcessing = true; - return AppBar; - })(); - exports.AppBar = AppBar; - _Base.Class.mix(AppBar, _Events.createEventProperties(_Constants.EventNames.beforeOpen, _Constants.EventNames.afterOpen, _Constants.EventNames.beforeClose, _Constants.EventNames.afterClose)); - // addEventListener, removeEventListener, dispatchEvent - _Base.Class.mix(AppBar, _Control.DOMEventMixin); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -/// -define('WinJS/Controls/AppBar',["require", "exports", '../Core/_Base'], function (require, exports, _Base) { - var module = null; - _Base.Namespace.define("WinJS.UI", { - AppBar: { - get: function () { - if (!module) { - require(["./AppBar/_AppBar"], function (m) { - module = m; - }); - } - return module.AppBar; - } - } - }); -}); - -// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information. -define('ui',[ - 'WinJS/Core/_WinJS', - 'WinJS/VirtualizedDataSource', - 'WinJS/Controls/IntrinsicControls', - 'WinJS/Controls/ListView', - 'WinJS/Controls/FlipView', - 'WinJS/Controls/ItemContainer', - 'WinJS/Controls/Repeater', - 'WinJS/Controls/DatePicker', - 'WinJS/Controls/TimePicker', - 'WinJS/Controls/BackButton', - 'WinJS/Controls/Rating', - 'WinJS/Controls/ToggleSwitch', - 'WinJS/Controls/SemanticZoom', - 'WinJS/Controls/Pivot', - 'WinJS/Controls/Hub', - 'WinJS/Controls/Flyout', - 'WinJS/Controls/_LegacyAppBar', - 'WinJS/Controls/Menu', - 'WinJS/Controls/SearchBox', - 'WinJS/Controls/SettingsFlyout', - 'WinJS/Controls/NavBar', - 'WinJS/Controls/Tooltip', - 'WinJS/Controls/ViewBox', - 'WinJS/Controls/ContentDialog', - 'WinJS/Controls/SplitView', - 'WinJS/Controls/SplitViewPaneToggle', - 'WinJS/Controls/ToolBar', - 'WinJS/Controls/AppBar', - ], function (_WinJS) { - "use strict"; - - return _WinJS; -}); - - require(['WinJS/Core/_WinJS', 'ui'], function (_WinJS) { - // WinJS always publishes itself to global - globalObject.WinJS = _WinJS; - if (typeof module !== 'undefined') { - // This is a CommonJS context so publish to exports - module.exports = _WinJS; - } - }); - return globalObject.WinJS; - })); -}()); - diff --git a/templates/winjs/template/source/package.appxmanifest b/templates/winjs/template/source/package.appxmanifest deleted file mode 100644 index e5c76ac793..0000000000 --- a/templates/winjs/template/source/package.appxmanifest +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - ::APP_TITLE:: - ::APP_COMPANY:: - images\storelogo.png - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/winjs/template/source/uwp-project.jsproj b/templates/winjs/template/source/uwp-project.jsproj deleted file mode 100644 index d32578b298..0000000000 --- a/templates/winjs/template/source/uwp-project.jsproj +++ /dev/null @@ -1,100 +0,0 @@ - - - - - Debug - AnyCPU - - - Debug - ARM - - - Debug - x64 - - - Debug - x86 - - - Release - AnyCPU - - - Release - ARM - true - - - Release - x64 - true - - - Release - x86 - true - - - - e9d48192-1008-49be-8a59-932a3ef1a1ca - - - - 14.0 - - - - - UAP - 10.0.15063.0 - 10.0.10586.0 - $(VersionNumberMajor).$(VersionNumberMinor) - en-US - - ::APP_FILE::_TemporaryKey.pfx - - - - - Designer - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/templates/winjs/template/source/uwp-project_TemporaryKey.pfx b/templates/winjs/template/source/uwp-project_TemporaryKey.pfx deleted file mode 100644 index 677fc35381..0000000000 Binary files a/templates/winjs/template/source/uwp-project_TemporaryKey.pfx and /dev/null differ diff --git a/templates/winjs/template/uwp-project.sln b/templates/winjs/template/uwp-project.sln deleted file mode 100644 index 31cf09fda9..0000000000 --- a/templates/winjs/template/uwp-project.sln +++ /dev/null @@ -1,48 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.16 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{262852C6-CD72-467D-83FE-5EEB1973A190}") = "::APP_FILE::", "source\::APP_FILE::.jsproj", "{E9D48192-1008-49BE-8A59-932A3EF1A1CA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|ARM = Debug|ARM - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|ARM = Release|ARM - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|ARM.ActiveCfg = Debug|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|ARM.Build.0 = Debug|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|ARM.Deploy.0 = Debug|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x64.ActiveCfg = Debug|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x64.Build.0 = Debug|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x64.Deploy.0 = Debug|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x86.ActiveCfg = Debug|x86 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x86.Build.0 = Debug|x86 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Debug|x86.Deploy.0 = Debug|x86 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|Any CPU.Build.0 = Release|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|Any CPU.Deploy.0 = Release|Any CPU - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|ARM.ActiveCfg = Release|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|ARM.Build.0 = Release|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|ARM.Deploy.0 = Release|ARM - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x64.ActiveCfg = Release|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x64.Build.0 = Release|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x64.Deploy.0 = Release|x64 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x86.ActiveCfg = Release|x86 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x86.Build.0 = Release|x86 - {E9D48192-1008-49BE-8A59-932A3EF1A1CA}.Release|x86.Deploy.0 = Release|x86 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/templates/winrt/appx/AppxManifest.xml b/templates/winrt/appx/AppxManifest.xml deleted file mode 100644 index ec28f1db0c..0000000000 --- a/templates/winrt/appx/AppxManifest.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - ::meta.title:: - ::meta.company:: - assetspkg\StoreLogo.png - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/winrt/assetspkg/LockScreenLogo.scale-200.png b/templates/winrt/assetspkg/LockScreenLogo.scale-200.png deleted file mode 100644 index 735f57adb5..0000000000 Binary files a/templates/winrt/assetspkg/LockScreenLogo.scale-200.png and /dev/null differ diff --git a/templates/winrt/assetspkg/SplashScreen.scale-200.png b/templates/winrt/assetspkg/SplashScreen.scale-200.png deleted file mode 100644 index 023e7f1fed..0000000000 Binary files a/templates/winrt/assetspkg/SplashScreen.scale-200.png and /dev/null differ diff --git a/templates/winrt/assetspkg/Square150x150Logo.scale-200.png b/templates/winrt/assetspkg/Square150x150Logo.scale-200.png deleted file mode 100644 index af49fec1a5..0000000000 Binary files a/templates/winrt/assetspkg/Square150x150Logo.scale-200.png and /dev/null differ diff --git a/templates/winrt/assetspkg/Square44x44Logo.scale-200.png b/templates/winrt/assetspkg/Square44x44Logo.scale-200.png deleted file mode 100644 index ce342a2ec8..0000000000 Binary files a/templates/winrt/assetspkg/Square44x44Logo.scale-200.png and /dev/null differ diff --git a/templates/winrt/assetspkg/Square44x44Logo.targetsize-24_altform-unplated.png b/templates/winrt/assetspkg/Square44x44Logo.targetsize-24_altform-unplated.png deleted file mode 100644 index f6c02ce97e..0000000000 Binary files a/templates/winrt/assetspkg/Square44x44Logo.targetsize-24_altform-unplated.png and /dev/null differ diff --git a/templates/winrt/assetspkg/StoreLogo.png b/templates/winrt/assetspkg/StoreLogo.png deleted file mode 100644 index 7385b56c0e..0000000000 Binary files a/templates/winrt/assetspkg/StoreLogo.png and /dev/null differ diff --git a/templates/winrt/assetspkg/Wide310x150Logo.scale-200.png b/templates/winrt/assetspkg/Wide310x150Logo.scale-200.png deleted file mode 100644 index 288995b397..0000000000 Binary files a/templates/winrt/assetspkg/Wide310x150Logo.scale-200.png and /dev/null differ diff --git a/templates/winrt/hxml/debug.hxml b/templates/winrt/hxml/debug.hxml deleted file mode 100644 index 4a7a166e43..0000000000 --- a/templates/winrt/hxml/debug.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cpp ::CPP_DIR:: --cp ::OUTPUT_DIR::/haxe ---macro keep("::APP_MAIN::") --D winrt --debug diff --git a/templates/winrt/hxml/final.hxml b/templates/winrt/hxml/final.hxml deleted file mode 100644 index 48760af001..0000000000 --- a/templates/winrt/hxml/final.hxml +++ /dev/null @@ -1,6 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D winrt --D final diff --git a/templates/winrt/hxml/release.hxml b/templates/winrt/hxml/release.hxml deleted file mode 100644 index d74c2747c1..0000000000 --- a/templates/winrt/hxml/release.hxml +++ /dev/null @@ -1,5 +0,0 @@ --main ApplicationMain ::HAXE_FLAGS:: --cp ::OUTPUT_DIR::/haxe --cpp ::CPP_DIR:: ---macro keep("::APP_MAIN::") --D winrt diff --git a/templates/winrt/scripts/newcertificate.ps1 b/templates/winrt/scripts/newcertificate.ps1 deleted file mode 100644 index 0843e709af..0000000000 --- a/templates/winrt/scripts/newcertificate.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -Get-ChildItem cert:\LocalMachine\My | Where-Object { $_.Subject -match "CN=::if APP_COMPANYID::APP_COMPANYID::else::OpenFL_Example::end::" } | Remove-Item -New-SelfSignedCertificate -Type Custom -Subject "CN=::if APP_COMPANYID::APP_COMPANYID::else::OpenFL_Example::end::" -KeyUsage DigitalSignature -FriendlyName OpenFLDisplayingCert -CertStoreLocation "Cert:\LocalMachine\My" -#Get-ChildItem cert:\LocalMachine\My | Where-Object { $_.Subject -match "CN=::if APP_COMPANYID::APP_COMPANYID::else::OpenFL_Example::end::" } -$pwd = ConvertTo-SecureString -String ::if APP_CERTIFICATE_PWD::APP_CERTIFICATE_PWD::else::"openflexample"::end:: -Force -AsPlainText -$thumbprint=(dir cert:\localmachine\My -recurse | where {$_.Subject -match "CN=::if APP_COMPANYID::APP_COMPANYID::else::OpenFL_Example::end::"} ).Thumbprint; -Export-PfxCertificate -cert "Cert:\LocalMachine\My\$thumbprint" -FilePath ::APP_FILE::.pfx -Password $pwd diff --git a/templates/winrt/static/BuildMain.xml b/templates/winrt/static/BuildMain.xml deleted file mode 100644 index e7a80812d2..0000000000 --- a/templates/winrt/static/BuildMain.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - ::foreach ndlls:: - ::end:: - -
- - - - - - - - -
- - - - -
- - - - - - - -
diff --git a/templates/winrt/static/Main.cpp b/templates/winrt/static/Main.cpp deleted file mode 100644 index ccdab16192..0000000000 --- a/templates/winrt/static/Main.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include - -#define DECLSPEC __declspec(dllexport) -#define SDLCALL __cdecl -#ifdef _MSC_VER -#pragma warning(disable:4103) -#pragma warning(disable:4447) -#endif -#pragma pack(push,8) -extern "C" { -extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved); -} -#pragma pack(pop) - -#include -#include - -#ifdef main -#undef main -#endif -#ifndef __WINRT__ -#define __WINRT__ -#endif -#ifndef SDL_BUILDING_WINRT -#define SDL_BUILDING_WINRT 1 -#endif - -#define LIME_SDL -#define LIME_OPENGL -#define LIME_CAIRO -#define NATIVE_TOOLKIT_SDL_ANGLE - -#ifndef SDL_WINRT_METADATA_FILE_AVAILABLE -#ifndef __cplusplus_winrt -#error Main.cpp must be compiled with /ZW, otherwise build errors due to missing .winmd files can occur. -#endif -#endif - -#ifdef _MSC_VER -#pragma comment(lib, "runtimeobject.lib") -#endif - -#define DEBUG_PRINTF -#ifdef DEBUG_PRINTF -# ifdef UNICODE -# define DLOG(fmt, ...) {wchar_t buf[1024];swprintf(buf,L"****LOG: %s(%d): %s \n [" fmt "]\n",__FILE__,__LINE__,__FUNCTION__, __VA_ARGS__);OutputDebugString(buf);} -# else -# define DLOG(fmt, ...) {char buf[1024];sprintf(buf,"****LOG: %s(%d): %s \n [" fmt "]\n",__FILE__,__LINE__,__FUNCTION__, __VA_ARGS__);OutputDebugString(buf);} -# endif -#else -# define DLOG(fmt, ...) {} -#endif - -extern "C" const char *hxRunLibrary (); -extern "C" void hxcpp_set_top_of_stack (); -extern "C" int zlib_register_prims (); -extern "C" int lime_cairo_register_prims (); -::foreach ndlls::::if (registerStatics):: -extern "C" int ::nameSafe::_register_prims ();::end::::end:: - - -int _main(int argc, char *argv[]) -{ - //DLOG("HELLO WORLD"); - //Sleep(10000); //uncomment to attach here in debugger - //DLOG("HELLO WORLD2"); - - try - { - hxcpp_set_top_of_stack (); - zlib_register_prims (); - lime_cairo_register_prims (); - ::foreach ndlls::::if (registerStatics):: - ::nameSafe::_register_prims ();::end::::end:: - - const char *err = NULL; - err = hxRunLibrary (); - if (err) { - DLOG("Error: %s\n", err); - } - } - catch (Dynamic e) - { - DLOG("Main Error\n",); -// __hx_dump_stack(); - return -1; - } - return 0; -} - -int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int) -{ - SDL_WinRTRunApp(_main, NULL); - return 0; -} - diff --git a/templates/winrt/temp/embed.resfiles b/templates/winrt/temp/embed.resfiles deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/templates/winrt/temp/layout.resfiles b/templates/winrt/temp/layout.resfiles deleted file mode 100644 index 67abc9c889..0000000000 --- a/templates/winrt/temp/layout.resfiles +++ /dev/null @@ -1 +0,0 @@ -//generate this file diff --git a/templates/winrt/temp/pri.resfiles b/templates/winrt/temp/pri.resfiles deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/templates/winrt/temp/priconfig.xml b/templates/winrt/temp/priconfig.xml deleted file mode 100644 index 1c6c21c81a..0000000000 --- a/templates/winrt/temp/priconfig.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/winrt/temp/resources.resfiles b/templates/winrt/temp/resources.resfiles deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/runtime/README.md b/tests/runtime/README.md index 9fa7bb5d9d..55a9bf0a91 100644 --- a/tests/runtime/README.md +++ b/tests/runtime/README.md @@ -4,7 +4,7 @@ Install git clone https://github.com/openfl/openfl-validation haxelib dev openfl-validation openfl-validation haxelib install munit - + Testing ------------- @@ -15,20 +15,15 @@ First, change to the openfl-validation directory: Next, you can test HTML5 and Flash using munit: haxelib run munit test - + Other targets can be tested using the normal OpenFL test commands: lime test windows - lime test windows -neko lime test mac - lime test mac -neko lime test linux - lime test linux -neko lime test ios lime test ios -simulator lime test android - lime test blackberry - lime test blackberry -simulator Contributing ------------- diff --git a/tests/runtime/run.sh b/tests/runtime/run.sh index 65916a5fde..6826d8c9a4 100755 --- a/tests/runtime/run.sh +++ b/tests/runtime/run.sh @@ -1,5 +1,4 @@ #!/bin/sh haxelib run munit gen -lime test neko lime test cpp haxelib run munit test diff --git a/tools/CommandLineTools.hx b/tools/CommandLineTools.hx index a5a11fadb9..ec557b511d 100644 --- a/tools/CommandLineTools.hx +++ b/tools/CommandLineTools.hx @@ -15,7 +15,6 @@ import sys.io.Process; import sys.FileSystem; import utils.publish.*; import utils.CreateTemplate; -import utils.JavaExternGenerator; import utils.PlatformSetup; @:access(lime.tools.HXProject) @@ -234,10 +233,6 @@ class CommandLineTools target = System.hostPlatform; targetFlags.set("cpp", ""); - case "neko": - target = System.hostPlatform; - targetFlags.set("neko", ""); - case "hl", "hashlink": target = System.hostPlatform; targetFlags.set("hl", ""); @@ -246,18 +241,6 @@ class CommandLineTools target = System.hostPlatform; targetFlags.set("cppia", ""); - case "java": - target = System.hostPlatform; - targetFlags.set("java", ""); - - case "nodejs": - target = System.hostPlatform; - targetFlags.set("nodejs", ""); - - case "cs": - target = System.hostPlatform; - targetFlags.set("cs", ""); - case "iphone", "iphoneos": target = Platform.IOS; @@ -269,10 +252,6 @@ class CommandLineTools target = Platform.HTML5; targetFlags.set("electron", ""); - case "firefox", "firefoxos": - target = Platform.FIREFOX; - overrides.haxedefs.set("firefoxos", ""); - case "appletv", "appletvos": target = Platform.TVOS; @@ -396,15 +375,6 @@ class CommandLineTools } } - case "publish": - if (words.length < 1 || words.length > 2) - { - Log.error("Incorrect number of arguments for command '" + command + "'"); - return; - } - - publishProject(); - case "installer", "copy-if-newer": // deprecated? @@ -585,21 +555,9 @@ class CommandLineTools case ANDROID: platform = new AndroidPlatform(command, project, targetFlags); - case BLACKBERRY: - - // platform = new BlackBerryPlatform (command, project, targetFlags); - case IOS: platform = new IOSPlatform(command, project, targetFlags); - case TIZEN: - - // platform = new TizenPlatform (command, project, targetFlags); - - case WEBOS: - - // platform = new WebOSPlatform (command, project, targetFlags); - case WINDOWS: platform = new WindowsPlatform(command, project, targetFlags); @@ -615,10 +573,6 @@ class CommandLineTools case HTML5: platform = new HTML5Platform(command, project, targetFlags); - // case FIREFOX: - - // platform = new FirefoxPlatform (command, project, targetFlags); - case WEB_ASSEMBLY: platform = new WebAssemblyPlatform(command, project, targetFlags); @@ -912,15 +866,12 @@ class CommandLineTools Log.println(""); Log.println(" \x1b[1mair\x1b[0m -- Create an AIR application"); Log.println(" \x1b[1mandroid\x1b[0m -- Create an Android application"); - // Log.println (" \x1b[1mblackberry\x1b[0m -- Create a BlackBerry application"); Log.println(" \x1b[1mflash\x1b[0m -- Create a Flash SWF application"); Log.println(" \x1b[1mhtml5\x1b[0m -- Create an HTML5 application"); Log.println(" \x1b[1mios\x1b[0m -- Create an iOS application"); Log.println(" \x1b[1mlinux\x1b[0m -- Create a Linux application"); Log.println(" \x1b[1mmac\x1b[0m -- Create a macOS application"); - // Log.println (" \x1b[1mtizen\x1b[0m -- Create a Tizen application"); Log.println(" \x1b[1mtvos\x1b[0m -- Create a tvOS application"); - // Log.println (" \x1b[1mwebos\x1b[0m -- Create a webOS application"); Log.println(" \x1b[1mwebassembly\x1b[0m -- Create a WebAssembly application"); Log.println(" \x1b[1mwindows\x1b[0m -- Create a Windows application"); @@ -930,15 +881,11 @@ class CommandLineTools Log.println(" \x1b[1mcpp\x1b[0m -- Alias for host platform (using \x1b[1m-cpp\x1b[0m)"); Log.println(" \x1b[1mneko\x1b[0m -- Alias for host platform (using \x1b[1m-neko\x1b[0m)"); Log.println(" \x1b[1mmacos\x1b[0m -- Alias for \x1b[1mmac\x1b[0m"); - Log.println(" \x1b[1mnodejs\x1b[0m -- Alias for host platform (using \x1b[1m-nodejs\x1b[0m)"); - Log.println(" \x1b[1mjava\x1b[0m -- Alias for host platform (using \x1b[1m-java\x1b[0m)"); - Log.println(" \x1b[1mcs\x1b[0m -- Alias for host platform (using \x1b[1m-cs\x1b[0m)"); Log.println(" \x1b[1mhl/hashlink\x1b[0m -- Alias for host platform (using \x1b[1m-hl\x1b[0m)"); Log.println(" \x1b[1mhlc\x1b[0m -- Alias for host platform (using \x1b[1m-hlc\x1b[0m)"); #if (lime >= "7.6.0") // Log.println(" \x1b[1mcppia\x1b[0m -- Alias for host platform (using \x1b[1m-cppia\x1b[0m)"); #end - Log.println(" \x1b[1muwp\x1b[0;3m/\x1b[0m\x1b[1mwinjs\x1b[0m -- Alias for \x1b[1mwindows -uwp\x1b[0m"); // Log.println (" \x1b[1miphone\x1b[0;3m/\x1b[0m\x1b[1miphoneos\x1b[0m -- \x1b[1mios\x1b[0m"); // Log.println (" \x1b[1miphonesim\x1b[0m -- Alias for \x1b[1mios -simulator\x1b[0m"); // Log.println (" \x1b[1mappletv\x1b[0;3m/\x1b[0m\x1b[1mappletvos\x1b[0m -- Alias for \x1b[1mtvos\x1b[0m"); @@ -1016,7 +963,6 @@ class CommandLineTools Log.println(" \x1b[3m(ios)\x1b[0m \x1b[1m-xcode\x1b[0m -- Launch the generated Xcode project"); } - // Log.println (" \x1b[3m(ios|blackberry|tizen|tvos|webos)\x1b[0m \x1b[1m-simulator\x1b[0m -- Target the device simulator"); Log.println(" \x1b[3m(ios|tvos)\x1b[0m \x1b[1m-simulator\x1b[0m -- Target the device simulator"); Log.println(" \x1b[3m(ios)\x1b[0m \x1b[1m-simulator -ipad\x1b[0m -- Build/test for the iPad Simulator"); Log.println(" \x1b[3m(android)\x1b[0m \x1b[1m-emulator\x1b[0m -- Target the device emulator"); @@ -1036,7 +982,6 @@ class CommandLineTools { Log.println(" \x1b[3m(html5|flash|webassembly)\x1b[0m \x1b[1m-nolaunch\x1b[0m -- Begin test server without launching"); // Log.println (" \x1b[3m(html5)\x1b[0m \x1b[1m-minify\x1b[0m -- Minify output using the Google Closure compiler"); - // Log.println (" \x1b[3m(html5)\x1b[0m \x1b[1m-minify -yui\x1b[0m -- Minify output using the YUI compressor"); Log.println(" \x1b[3m(html5|flash|webassembly)\x1b[0m \x1b[1m--port=\x1b[0;3mvalue\x1b[0m -- Set port for test server"); } @@ -1045,16 +990,11 @@ class CommandLineTools Log.println(""); Log.println(" \x1b[1m-watch\x1b[0m -- Execute the current command when the source changes"); Log.println(" \x1b[3m(linux)\x1b[0m \x1b[1m-rpi\x1b[0m -- Build for Raspberry Pi"); - Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-java\x1b[0m -- Build for Java instead of C++"); - Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-nodejs\x1b[0m -- Build for Node.js instead of C++"); - Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-cs\x1b[0m -- Build for C# instead of C++"); Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-hl\x1b[0m -- Build for HashLink/JIT instead of C++"); Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-hlc\x1b[0m -- Build for HashLink/C instead of C++"); #if (lime >= "7.6.0") // Log.println(" \x1b[3m(windows|mac|linux)\x1b[0m \x1b[1m-cppia\x1b[0m -- Build for CPPIA instead of C++"); #end - Log.println(" \x1b[3m(windows)\x1b[0m \x1b[1m-winjs\x1b[0m -- Build for WinJS instead of C++ (implies UWP)"); - Log.println(" \x1b[3m(windows)\x1b[0m \x1b[1m-uwp\x1b[0m -- Build for Universal Windows Platform"); Log.println(" \x1b[3m(html5)\x1b[0m \x1b[1m-electron\x1b[0m -- Target Electron instead of the browser"); if (command != "run" && command != "trace") @@ -1234,14 +1174,6 @@ class CommandLineTools // var json = Json.stringify (details); // Sys.print (json); } - else if (targetFlags.exists("java-externs")) - { - var config = ConfigHelper.getConfig(); - var sourcePath = words[0]; - var targetPath = words[1]; - - new JavaExternGenerator(config, sourcePath, targetPath); - } } private function getBuildNumber(project:HXProject, increment:Bool = true):Void @@ -1514,10 +1446,6 @@ class CommandLineTools target = System.hostPlatform; targetFlags.set("cpp", ""); - case "neko": - target = System.hostPlatform; - targetFlags.set("neko", ""); - case "hl", "hashlink": target = System.hostPlatform; targetFlags.set("hl", ""); @@ -1531,18 +1459,6 @@ class CommandLineTools target = System.hostPlatform; targetFlags.set("cppia", ""); - case "java": - target = System.hostPlatform; - targetFlags.set("java", ""); - - case "nodejs": - target = System.hostPlatform; - targetFlags.set("nodejs", ""); - - case "cs": - target = System.hostPlatform; - targetFlags.set("cs", ""); - case "iphone", "iphoneos": target = Platform.IOS; @@ -1554,10 +1470,6 @@ class CommandLineTools target = Platform.HTML5; targetFlags.set("electron", ""); - case "firefox", "firefoxos": - target = Platform.FIREFOX; - overrides.haxedefs.set("firefoxos", ""); - case "mac", "macos": target = Platform.MAC; overrides.haxedefs.set("macos", ""); @@ -1570,15 +1482,6 @@ class CommandLineTools target = Platform.WEB_ASSEMBLY; targetFlags.set("webassembly", ""); - case "winjs", "uwp": - target = Platform.WINDOWS; - targetFlags.set("uwp", ""); - targetFlags.set("winjs", ""); - - case "winrt": - target = Platform.WINDOWS; - targetFlags.set("winrt", ""); - default: target = cast targetName.toLowerCase(); } @@ -2295,27 +2198,6 @@ class CommandLineTools } } - private function publishProject() - { - switch (words[words.length - 1]) - { - case "firefox": - var project = initializeProject(null, "firefox"); - - Log.info("", Log.accentColor + "Using publishing target: FIREFOX MARKETPLACE" + Log.resetColor); - - // if (FirefoxMarketplace.isValid (project)) { - // - // buildProject (project, "build"); - // - // Log.info ("", "\n" + Log.accentColor + "Running command: PUBLISH" + Log.resetColor); - // - // FirefoxMarketplace.publish (project); - // - // } - } - } - private function updateLibrary():Void { if ((words.length < 1 && command != "upgrade") || words.length > 1) diff --git a/tools/platforms/LinuxPlatform.hx b/tools/platforms/LinuxPlatform.hx index 916048178f..e48c3bff7a 100644 --- a/tools/platforms/LinuxPlatform.hx +++ b/tools/platforms/LinuxPlatform.hx @@ -13,8 +13,6 @@ import lime.tools.AssetType; import lime.tools.CPPHelper; import lime.tools.DeploymentHelper; import lime.tools.HXProject; -import lime.tools.JavaHelper; -import lime.tools.NekoHelper; import lime.tools.NodeJSHelper; import lime.tools.Orientation; import lime.tools.Platform; @@ -133,11 +131,7 @@ class LinuxPlatform extends PlatformTarget } } - if (project.targetFlags.exists("neko")) - { - targetType = "neko"; - } - else if (project.targetFlags.exists("hl") || targetFlags.exists("hlc")) + if (project.targetFlags.exists("hl") || targetFlags.exists("hlc")) { targetType = "hl"; is64 = true; @@ -155,14 +149,6 @@ class LinuxPlatform extends PlatformTarget } } } - else if (project.targetFlags.exists("nodejs")) - { - targetType = "nodejs"; - } - else if (project.targetFlags.exists("java")) - { - targetType = "java"; - } else { targetType = "cpp"; @@ -207,17 +193,7 @@ class LinuxPlatform extends PlatformTarget } } - if (targetType == "neko") - { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - NekoHelper.createExecutable(project.templatePaths, "linux" + (( System.hostArchitecture == ARMV7 || System.hostArchitecture == ARM64)?"Arm":"") + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath); - NekoHelper.copyLibraries(project.templatePaths, "linux" + (is64 ? "64" : ""), applicationDirectory); - - } - else if (targetType == "hl") + if (targetType == "hl") { System.runCommand("", "haxe", [hxml]); @@ -243,37 +219,6 @@ class LinuxPlatform extends PlatformTarget System.runCommand("", command.shift(), command); } } - else if (targetType == "nodejs") - { - System.runCommand("", "haxe", [hxml]); - // NekoHelper.createExecutable (project.templatePaths, "linux" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath); - // NekoHelper.copyLibraries (project.templatePaths, "linux" + (is64 ? "64" : ""), applicationDirectory); - } - else if (targetType == "java") - { - var libPath = Path.combine(Haxelib.getPath(new Haxelib("lime")), "templates/java/lib/"); - - System.runCommand("", "haxe", [hxml, "-java-lib", libPath + "disruptor.jar", "-java-lib", libPath + "lwjgl.jar"]); - // System.runCommand ("", "haxe", [ hxml ]); - - if (noOutput) return; - - var haxeVersion = project.environment.get("haxe_ver"); - var haxeVersionString = "3404"; - - if (haxeVersion.length > 4) - { - haxeVersionString = haxeVersion.charAt(0) - + haxeVersion.charAt(2) - + (haxeVersion.length == 5 ? "0" + haxeVersion.charAt(4) : haxeVersion.charAt(4) + haxeVersion.charAt(5)); - } - - System.runCommand(targetDirectory + "/obj", "haxelib", ["run", "hxjava", "hxjava_build.txt", "--haxe-version", haxeVersionString]); - System.recursiveCopy(targetDirectory + "/obj/lib", Path.combine(applicationDirectory, "lib")); - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", - Path.combine(applicationDirectory, project.app.file + ".jar")); - JavaHelper.copyLibraries(project.templatePaths, "Linux" + (is64 ? "64" : ""), applicationDirectory); - } else { var haxeArgs = [hxml]; @@ -377,7 +322,7 @@ class LinuxPlatform extends PlatformTarget } } - if (System.hostPlatform != WINDOWS && (targetType != "nodejs" && targetType != "java")) + if (System.hostPlatform != WINDOWS) { System.runCommand("", "chmod", ["755", executablePath]); } @@ -451,12 +396,6 @@ class LinuxPlatform extends PlatformTarget { case "hl": hxml.hl = "_.hl"; - case "neko": - hxml.neko = "_.n"; - case "java": - hxml.java = "_"; - case "nodejs": - hxml.js = "_.js"; default: hxml.cpp = "_"; } @@ -532,15 +471,7 @@ class LinuxPlatform extends PlatformTarget arguments.push("-verbose"); } - if (targetType == "nodejs") - { - NodeJSHelper.run(project, targetDirectory + "/bin/ApplicationMain.js", arguments); - } - else if (targetType == "java") - { - System.runCommand(applicationDirectory, "java", ["-jar", project.app.file + ".jar"].concat(arguments)); - } - else if (project.target == System.hostPlatform) + if (project.target == System.hostPlatform) { arguments = arguments.concat(["-livereload"]); System.runCommand(applicationDirectory, "./" + Path.withoutDirectory(executablePath), arguments); diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 11f997d1b6..c7a021c358 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -11,15 +11,12 @@ import lime.tools.Architecture; import lime.tools.AssetHelper; import lime.tools.AssetType; import lime.tools.CPPHelper; -import lime.tools.CSHelper; import lime.tools.DeploymentHelper; import lime.tools.GUID; import lime.tools.HashlinkHelper; import lime.tools.HXProject; import lime.tools.Icon; import lime.tools.IconHelper; -import lime.tools.JavaHelper; -import lime.tools.NekoHelper; import lime.tools.NodeJSHelper; import lime.tools.Orientation; import lime.tools.Platform; @@ -123,11 +120,7 @@ class MacPlatform extends PlatformTarget } } - if (project.targetFlags.exists("neko") || project.target != System.hostPlatform) - { - targetType = "neko"; - } - else if (project.targetFlags.exists("hl") || project.targetFlags.exists("hlc")) + if (project.targetFlags.exists("hl") || project.targetFlags.exists("hlc")) { targetType = "hl"; var hlVer = project.haxedefs.get("hl-ver"); @@ -144,18 +137,6 @@ class MacPlatform extends PlatformTarget } } } - else if (project.targetFlags.exists("java")) - { - targetType = "java"; - } - else if (project.targetFlags.exists("nodejs")) - { - targetType = "nodejs"; - } - else if (project.targetFlags.exists("cs")) - { - targetType = "cs"; - } else { targetType = "cpp"; @@ -202,16 +183,7 @@ class MacPlatform extends PlatformTarget } } - if (targetType == "neko") - { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - NekoHelper.createExecutable(project.templatePaths, "mac" + dirSuffix.toLowerCase(), targetDirectory + "/obj/ApplicationMain.n", executablePath); - NekoHelper.copyLibraries(project.templatePaths, "mac" + dirSuffix.toLowerCase(), executableDirectory); - } - else if (targetType == "hl") + if (targetType == "hl") { System.runCommand("", "haxe", [hxml]); @@ -277,43 +249,6 @@ class MacPlatform extends PlatformTarget System.runCommand("", "chmod", ["755", executablePath]); } } - else if (targetType == "java") - { - var libPath = Path.combine(Haxelib.getPath(new Haxelib("lime")), "templates/java/lib/"); - - System.runCommand("", "haxe", [hxml, "-java-lib", libPath + "disruptor.jar", "-java-lib", libPath + "lwjgl.jar"]); - - if (noOutput) return; - - Haxelib.runCommand(targetDirectory + "/obj", ["run", "hxjava", "hxjava_build.txt", "--haxe-version", "3103"]); - System.recursiveCopy(targetDirectory + "/obj/lib", Path.combine(executableDirectory, "lib")); - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", - Path.combine(executableDirectory, project.app.file + ".jar")); - JavaHelper.copyLibraries(project.templatePaths, "Mac" + dirSuffix, executableDirectory); - } - else if (targetType == "nodejs") - { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - // NekoHelper.createExecutable (project.templatePaths, "Mac" + dirSuffix, targetDirectory + "/obj/ApplicationMain.n", executablePath); - // NekoHelper.copyLibraries (project.templatePaths, "Mac" + dirSuffix, executableDirectory); - } - else if (targetType == "cs") - { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - CSHelper.copySourceFiles(project.templatePaths, targetDirectory + "/obj/src"); - var txtPath = targetDirectory + "/obj/hxcs_build.txt"; - CSHelper.addSourceFiles(txtPath, CSHelper.ndllSourceFiles); - CSHelper.addGUID(txtPath, GUID.uuid()); - CSHelper.compile(project, targetDirectory + "/obj", targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : ""), "x64", "desktop"); - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath + ".exe"); - File.saveContent(executablePath, "#!/bin/sh\nmono ${PWD}/" + project.app.file + ".exe"); - } else { var haxeArgs = [hxml, "-D", "HXCPP_CLANG"]; @@ -355,7 +290,7 @@ class MacPlatform extends PlatformTarget } } - if (System.hostPlatform != WINDOWS && targetType != "nodejs" && targetType != "java" && sys.FileSystem.exists(executablePath)) + if (System.hostPlatform != WINDOWS && sys.FileSystem.exists(executablePath)) { System.runCommand("", "chmod", ["755", executablePath]); } @@ -420,12 +355,6 @@ class MacPlatform extends PlatformTarget { case "hl": hxml.hl = "_.hl"; - case "neko": - hxml.neko = "_.n"; - case "java": - hxml.java = "_"; - case "nodejs": - hxml.js = "_.js"; default: hxml.cpp = "_"; } @@ -495,15 +424,7 @@ class MacPlatform extends PlatformTarget arguments.push("-verbose"); } - if (targetType == "nodejs") - { - NodeJSHelper.run(project, executableDirectory + "/ApplicationMain.js", arguments); - } - else if (targetType == "java") - { - System.runCommand(executableDirectory, "java", ["-jar", project.app.file + ".jar"].concat(arguments)); - } - else if (project.target == System.hostPlatform) + if (project.target == System.hostPlatform) { arguments = arguments.concat(["-livereload"]); System.runCommand(executableDirectory, "./" + Path.withoutDirectory(executablePath), arguments); diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 24bc8f2f85..9d27099548 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -12,16 +12,13 @@ import lime.tools.Asset; import lime.tools.AssetHelper; import lime.tools.AssetType; import lime.tools.CPPHelper; -import lime.tools.CSHelper; import lime.tools.DeploymentHelper; import lime.tools.GUID; import lime.tools.HTML5Helper; import lime.tools.HXProject; import lime.tools.Icon; import lime.tools.IconHelper; -import lime.tools.JavaHelper; import lime.tools.ModuleHelper; -import lime.tools.NekoHelper; import lime.tools.NodeJSHelper; import lime.tools.Orientation; import lime.tools.Platform; @@ -97,27 +94,18 @@ class WindowsPlatform extends PlatformTarget title: "" }; - if (project.targetFlags.exists("uwp") || project.targetFlags.exists("winjs")) + switch (System.hostArchitecture) { - defaults.window.width = 0; - defaults.window.height = 0; - defaults.window.fps = 60; - } - else - { - switch (System.hostArchitecture) - { - case ARMV6: - defaults.architectures = [ARMV6]; - case ARMV7: - defaults.architectures = [ARMV7]; - case X86: - defaults.architectures = [X86]; - case X64: - defaults.architectures = [X64]; - default: - defaults.architectures = []; - } + case ARMV6: + defaults.architectures = [ARMV6]; + case ARMV7: + defaults.architectures = [ARMV7]; + case X86: + defaults.architectures = [X86]; + case X64: + defaults.architectures = [X64]; + default: + defaults.architectures = []; } defaults.window.allowHighDPI = false; @@ -135,15 +123,7 @@ class WindowsPlatform extends PlatformTarget project.architectures.remove(excludeArchitecture); } - if (project.targetFlags.exists("uwp") || project.targetFlags.exists("winjs")) - { - targetType = "winjs"; - } - else if (project.targetFlags.exists("neko")) - { - targetType = "neko"; - } - else if (project.targetFlags.exists("hl") || targetFlags.exists("hlc")) + if (project.targetFlags.exists("hl") || targetFlags.exists("hlc")) { targetType = "hl"; is64 = !project.flags.exists("32") && !project.flags.exists("x86_32"); @@ -166,22 +146,6 @@ class WindowsPlatform extends PlatformTarget targetType = "cppia"; is64 = true; } - else if (project.targetFlags.exists("nodejs")) - { - targetType = "nodejs"; - } - else if (project.targetFlags.exists("cs")) - { - targetType = "cs"; - } - else if (project.targetFlags.exists("java")) - { - targetType = "java"; - } - else if (project.targetFlags.exists("winrt")) - { - targetType = "winrt"; - } else { targetType = "cpp"; @@ -191,29 +155,10 @@ class WindowsPlatform extends PlatformTarget { if (architecture == Architecture.X64) { - if ((targetType == "cpp" || targetType == "winrt")) + if (targetType == "cpp") { is64 = true; } - else if (targetType == "neko") - { - try - { - var process = new Process("haxe", ["-version"]); - var haxeVersion = StringTools.trim(process.stderr.readAll().toString()); - if (haxeVersion == "") - { - haxeVersion = StringTools.trim(process.stdout.readAll().toString()); - } - process.close(); - - if (Std.parseInt(haxeVersion.split(".")[0]) >= 4) - { - is64 = true; - } - } - catch (e:Dynamic) {} - } } } @@ -223,18 +168,11 @@ class WindowsPlatform extends PlatformTarget case "hl": project.targetFlags.exists("hlc") ? "hlc" : targetType; default: targetType; } + targetDirectory = Path.combine(project.app.path, project.config.getString("windows.output-directory", defaultTargetDirectory)); targetDirectory = StringTools.replace(targetDirectory, "arch64", is64 ? "64" : ""); - - if (targetType == "winjs") - { - outputFile = targetDirectory + "/source/js/" + project.app.file + ".js"; - } - else - { - applicationDirectory = targetDirectory + "/bin/"; - executablePath = applicationDirectory + project.app.file + ".exe"; - } + applicationDirectory = targetDirectory + "/bin/"; + executablePath = applicationDirectory + project.app.file + ".exe"; } public override function build():Void @@ -250,384 +188,198 @@ class WindowsPlatform extends PlatformTarget icons = [new Icon(System.findTemplate(project.templatePaths, "default/icon.svg"))]; } - if (targetType == "winjs") + for (dependency in project.dependencies) { - ModuleHelper.buildModules(project, targetDirectory, targetDirectory); - - if (project.app.main != null) + if (StringTools.endsWith(dependency.path, ".dll")) { - System.runCommand("", "haxe", [hxml]); - - // start by finding visual studio - var programFilesX86 = Sys.getEnv("ProgramFiles(x86)"); - var vswhereCommand = programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; - var vswhereOutput = System.runProcess("", vswhereCommand, ["-latest", "-products", "*", "-requires", "Microsoft.Component.MSBuild", "-property", "installationPath"]); - var visualStudioPath = StringTools.trim(vswhereOutput); - // then, find MSBuild inside visual studio - var msBuildPath = visualStudioPath + "\\MSBuild\\Current\\Bin\\MSBuild.exe"; - if (!FileSystem.exists(msBuildPath)) - { - // fallback for VS 2017, which didn't use Current - msBuildPath = visualStudioPath + "\\MSBuild\\15.0\\Bin\\MSBuild.exe"; - if (!FileSystem.exists(msBuildPath)) - { - Log.error("MSBuild not found"); - return; - } - } - var args = [ - Path.tryFullPath(targetDirectory + "/source/" + project.app.file + ".jsproj"), - "/p:Configuration=Release" - ]; - - System.runCommand("", msBuildPath, args); - if (noOutput) return; - - if (project.targetFlags.exists("webgl")) - { - System.copyFile(targetDirectory + "/source/ApplicationMain.js", outputFile); - } - - if (project.modules.iterator().hasNext()) - { - ModuleHelper.patchFile(outputFile); - } - - if (project.targetFlags.exists("minify") || buildType == "final") - { - HTML5Helper.minify(project, targetDirectory + outputFile); - } + var fileName = Path.withoutDirectory(dependency.path); + copyIfNewer(dependency.path, applicationDirectory + "/" + fileName); } } - else + + if (!project.targetFlags.exists("static") || targetType != "cpp") { - for (dependency in project.dependencies) - { - if (StringTools.endsWith(dependency.path, ".dll")) - { - var fileName = Path.withoutDirectory(dependency.path); - copyIfNewer(dependency.path, applicationDirectory + "/" + fileName); - } - } + var targetSuffix = (targetType == "hl") ? ".hdll" : null; - if (targetType == "winrt") + for (ndll in project.ndlls) { - if (!project.targetFlags.exists("static")) + // TODO: Support single binary for HashLink + if (targetType == "hl") { - for (ndll in project.ndlls) - { - ProjectHelper.copyLibrary(project, ndll, "WinRT" + (is64 ? "64" : ""), "", - (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", - applicationDirectory, project.debug, null); - } + ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", ".hdll", applicationDirectory, project.debug, + targetSuffix); + ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", ".lib", applicationDirectory, project.debug, + ".lib"); } - } - else if (!project.targetFlags.exists("static") || targetType != "cpp") - { - var targetSuffix = (targetType == "hl") ? ".hdll" : null; - - for (ndll in project.ndlls) + else { - // TODO: Support single binary for HashLink - if (targetType == "hl") - { - ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", ".hdll", applicationDirectory, project.debug, - targetSuffix); - ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", ".lib", applicationDirectory, project.debug, - ".lib"); - } - else - { - ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", - (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", - applicationDirectory, project.debug, targetSuffix); - } + ProjectHelper.copyLibrary(project, ndll, "Windows" + (is64 ? "64" : ""), "", + (ndll.haxelib != null && (ndll.haxelib.name == "hxcpp" || ndll.haxelib.name == "hxlibc")) ? ".dll" : ".ndll", + applicationDirectory, project.debug, targetSuffix); } } + } - // IconHelper.createIcon (project.icons, 32, 32, Path.combine (applicationDirectory, "icon.png")); - - if (targetType == "neko") - { - System.runCommand("", "haxe", [hxml]); + // IconHelper.createIcon (project.icons, 32, 32, Path.combine (applicationDirectory, "icon.png")); - if (noOutput) return; + if (targetType == "hl") + { + System.runCommand("", "haxe", [hxml]); - var iconPath = Path.combine(applicationDirectory, "icon.ico"); + if (noOutput) return; - if (!IconHelper.createWindowsIcon(icons, iconPath)) - { - iconPath = null; - } + HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath, is64); - NekoHelper.createWindowsExecutable(project.templatePaths, targetDirectory + "/obj/ApplicationMain.n", executablePath, iconPath); - NekoHelper.copyLibraries(project.templatePaths, "windows" + (is64 ? "64" : ""), applicationDirectory); - } - else if (targetType == "hl") + if (project.targetFlags.exists("hlc")) { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - HashlinkHelper.copyHashlink(project, targetDirectory, applicationDirectory, executablePath, is64); - - if (project.targetFlags.exists("hlc")) + var command:Array = null; + if (project.targetFlags.exists("gcc")) { - var command:Array = null; - if (project.targetFlags.exists("gcc")) + command = ["gcc", "-O3", "-o", executablePath, "-std=c11", "-Wl,-subsystem,windows", "-I", Path.combine(targetDirectory, "obj"), Path.combine(targetDirectory, "obj/ApplicationMain.c"), "C:/Windows/System32/dbghelp.dll"]; + for (file in System.readDirectory(applicationDirectory)) { - command = ["gcc", "-O3", "-o", executablePath, "-std=c11", "-Wl,-subsystem,windows", "-I", Path.combine(targetDirectory, "obj"), Path.combine(targetDirectory, "obj/ApplicationMain.c"), "C:/Windows/System32/dbghelp.dll"]; - for (file in System.readDirectory(applicationDirectory)) + switch Path.extension(file) { - switch Path.extension(file) - { - case "dll", "hdll": - // ensure the executable knows about every library - command.push(file); - default: - } + case "dll", "hdll": + // ensure the executable knows about every library + command.push(file); + default: } } - else - { - // start by finding visual studio - var programFilesX86 = Sys.getEnv("ProgramFiles(x86)"); - var vswhereCommand = programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; - var vswhereOutput = System.runProcess("", vswhereCommand, ["-latest", "-products", "*", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath"]); - var visualStudioPath = StringTools.trim(vswhereOutput); - var vcvarsallPath = visualStudioPath + "\\VC\\Auxiliary\\Build\\vcvarsall.bat"; - // this command sets up the environment variables and things that visual studio requires - var vcvarsallCommand = [vcvarsallPath, "x64"].map(arg -> ~/([&|\(\)<>\^ ])/g.replace(arg, "^$1")); - // this command runs the cl.exe c compiler from visual studio - var clCommand = ["cl.exe", "/Ox", "/Fe:" + executablePath, "-I", Path.combine(targetDirectory, "obj"), Path.combine(targetDirectory, "obj/ApplicationMain.c")]; - for (file in System.readDirectory(applicationDirectory)) - { - switch Path.extension(file) - { - case "lib": - // ensure the executable knows about every library - clCommand.push(file); - default: - } - } - clCommand.push("/link"); - clCommand.push("/subsystem:windows"); - clCommand = clCommand.map(arg -> ~/([&|\(\)<>\^ ])/g.replace(arg, "^$1")); - // combine both commands into one - command = ["cmd.exe", "/s", "/c", vcvarsallCommand.join(" ") + " && " + clCommand.join(" ")]; - } - System.runCommand("", command.shift(), command); } - - for (file in System.readDirectory(applicationDirectory)) + else { - switch Path.extension(file) + // start by finding visual studio + var programFilesX86 = Sys.getEnv("ProgramFiles(x86)"); + var vswhereCommand = programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe"; + var vswhereOutput = System.runProcess("", vswhereCommand, ["-latest", "-products", "*", "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath"]); + var visualStudioPath = StringTools.trim(vswhereOutput); + var vcvarsallPath = visualStudioPath + "\\VC\\Auxiliary\\Build\\vcvarsall.bat"; + // this command sets up the environment variables and things that visual studio requires + var vcvarsallCommand = [vcvarsallPath, "x64"].map(arg -> ~/([&|\(\)<>\^ ])/g.replace(arg, "^$1")); + // this command runs the cl.exe c compiler from visual studio + var clCommand = ["cl.exe", "/Ox", "/Fe:" + executablePath, "-I", Path.combine(targetDirectory, "obj"), Path.combine(targetDirectory, "obj/ApplicationMain.c")]; + for (file in System.readDirectory(applicationDirectory)) { - case "lib": - // lib files required only for hlc compilation - System.deleteFile(file); - default: + switch Path.extension(file) + { + case "lib": + // ensure the executable knows about every library + clCommand.push(file); + default: + } } + clCommand.push("/link"); + clCommand.push("/subsystem:windows"); + clCommand = clCommand.map(arg -> ~/([&|\(\)<>\^ ])/g.replace(arg, "^$1")); + // combine both commands into one + command = ["cmd.exe", "/s", "/c", vcvarsallCommand.join(" ") + " && " + clCommand.join(" ")]; } - - var iconPath = Path.combine(applicationDirectory, "icon.ico"); - - if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS) - { - var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths); - System.runCommand("", System.findTemplate(templates, "bin/ReplaceVistaIcon.exe"), [executablePath, iconPath, "1"], true, true); - } + System.runCommand("", command.shift(), command); } - else if (targetType == "cppia") - { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - System.copyFile(Path.combine(Haxelib.getPath(new Haxelib("hxcpp")), "bin/Windows64/Cppia.exe"), executablePath); - System.copyFile(targetDirectory + "/obj/ApplicationMain.cppia", Path.combine(applicationDirectory, "script.cppia")); - var iconPath = Path.combine(applicationDirectory, "icon.ico"); - - if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS) + for (file in System.readDirectory(applicationDirectory)) + { + switch Path.extension(file) { - var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths); - System.runCommand("", System.findTemplate(templates, "bin/ReplaceVistaIcon.exe"), [executablePath, iconPath, "1"], true, true); + case "lib": + // lib files required only for hlc compilation + System.deleteFile(file); + default: } } - else if (targetType == "nodejs") - { - System.runCommand("", "haxe", [hxml]); - if (noOutput) return; + var iconPath = Path.combine(applicationDirectory, "icon.ico"); - // NekoHelper.createExecutable (project.templatePaths, "windows" + (is64 ? "64" : ""), targetDirectory + "/obj/ApplicationMain.n", executablePath); - // NekoHelper.copyLibraries (project.templatePaths, "windows" + (is64 ? "64" : ""), applicationDirectory); - } - else if (targetType == "cs") + if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS) { - System.runCommand("", "haxe", [hxml]); - - if (noOutput) return; - - CSHelper.copySourceFiles(project.templatePaths, targetDirectory + "/obj/src"); - var txtPath = targetDirectory + "/obj/hxcs_build.txt"; - CSHelper.addSourceFiles(txtPath, CSHelper.ndllSourceFiles); - CSHelper.addGUID(txtPath, GUID.uuid()); - CSHelper.compile(project, targetDirectory + "/obj", applicationDirectory + project.app.file, "x86", "desktop"); + var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths); + System.runCommand("", System.findTemplate(templates, "bin/ReplaceVistaIcon.exe"), [executablePath, iconPath, "1"], true, true); } - else if (targetType == "java") - { - var libPath = Path.combine(Haxelib.getPath(new Haxelib("lime")), "templates/java/lib/"); - - System.runCommand("", "haxe", [hxml, "-java-lib", libPath + "disruptor.jar", "-java-lib", libPath + "lwjgl.jar"]); - // System.runCommand ("", "haxe", [ hxml ]); + } + else if (targetType == "cppia") + { + System.runCommand("", "haxe", [hxml]); - if (noOutput) return; + if (noOutput) return; - var haxeVersion = project.environment.get("haxe_ver"); - var haxeVersionString = "3404"; + System.copyFile(Path.combine(Haxelib.getPath(new Haxelib("hxcpp")), "bin/Windows64/Cppia.exe"), executablePath); + System.copyFile(targetDirectory + "/obj/ApplicationMain.cppia", Path.combine(applicationDirectory, "script.cppia")); - if (haxeVersion.length > 4) - { - haxeVersionString = haxeVersion.charAt(0) - + haxeVersion.charAt(2) - + (haxeVersion.length == 5 ? "0" + haxeVersion.charAt(4) : haxeVersion.charAt(4) + haxeVersion.charAt(5)); - } + var iconPath = Path.combine(applicationDirectory, "icon.ico"); - System.runCommand(targetDirectory + "/obj", "haxelib", ["run", "hxjava", "hxjava_build.txt", "--haxe-version", haxeVersionString]); - System.recursiveCopy(targetDirectory + "/obj/lib", Path.combine(applicationDirectory, "lib")); - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-Debug" : "") + ".jar", - Path.combine(applicationDirectory, project.app.file + ".jar")); - JavaHelper.copyLibraries(project.templatePaths, "Windows" + (is64 ? "64" : ""), applicationDirectory); - } - else if (targetType == "winrt") + if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS) { - var haxeArgs = [hxml]; - var flags = []; + var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths); + System.runCommand("", System.findTemplate(templates, "bin/ReplaceVistaIcon.exe"), [executablePath, iconPath, "1"], true, true); + } + } + else + { + var haxeArgs = [hxml, "-D", "resourceFile=ApplicationMain.rc"]; + var flags = ["-DresourceFile=ApplicationMain.rc"]; + if (is64) + { haxeArgs.push("-D"); - haxeArgs.push("winrt"); - flags.push("-Dwinrt"); - - // TODO: ARM support - - if (is64) - { - haxeArgs.push("-D"); - haxeArgs.push("HXCPP_M64"); - flags.push("-DHXCPP_M64"); - } - else - { - flags.push("-DHXCPP_M32"); - } - - if (!project.environment.exists("SHOW_CONSOLE")) - { - haxeArgs.push("-D"); - haxeArgs.push("no_console"); - flags.push("-Dno_console"); - } - - if (!project.targetFlags.exists("static")) - { - System.runCommand("", "haxe", haxeArgs); - - if (noOutput) return; - - CPPHelper.compile(project, targetDirectory + "/obj", flags); - - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath); - } - else - { - System.runCommand("", "haxe", haxeArgs.concat(["-D", "static_link"])); - - if (noOutput) return; - - CPPHelper.compile(project, targetDirectory + "/obj", flags.concat(["-Dstatic_link"])); - CPPHelper.compile(project, targetDirectory + "/obj", flags, "BuildMain.xml"); - - System.copyFile(targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath); - } - - // TODO createWinrtIcons - // var iconPath = Path.combine(applicationDirectory, "icon.ico"); - - // if (IconHelper.createWindowsIcon(icons, iconPath) && System.hostPlatform == WINDOWS) - // { - // var templates = [Haxelib.getPath(new Haxelib(#if lime "lime" #else "hxp" #end)) + "/templates"].concat(project.templatePaths); - // System.runCommand("", System.findTemplate(templates, "bin/ReplaceVistaIcon.exe"), [executablePath, iconPath, "1"], true, true); - // } + haxeArgs.push("HXCPP_M64"); + flags.push("-DHXCPP_M64"); } else { - var haxeArgs = [hxml, "-D", "resourceFile=ApplicationMain.rc"]; - var flags = ["-DresourceFile=ApplicationMain.rc"]; - - if (is64) - { - haxeArgs.push("-D"); - haxeArgs.push("HXCPP_M64"); - flags.push("-DHXCPP_M64"); - } - else - { - flags.push("-DHXCPP_M32"); - } + flags.push("-DHXCPP_M32"); + } - if (!project.environment.exists("SHOW_CONSOLE")) - { - haxeArgs.push("-D"); - haxeArgs.push("no_console"); - flags.push("-Dno_console"); - } + if (!project.environment.exists("SHOW_CONSOLE")) + { + haxeArgs.push("-D"); + haxeArgs.push("no_console"); + flags.push("-Dno_console"); + } - if (!project.targetFlags.exists("static")) - { - System.runCommand("", "haxe", haxeArgs); + if (!project.targetFlags.exists("static")) + { + System.runCommand("", "haxe", haxeArgs); - if (noOutput) return; + if (noOutput) return; - IconHelper.createWindowsIcon(icons, Path.combine(targetDirectory + "/obj", "ApplicationMain.ico")); + IconHelper.createWindowsIcon(icons, Path.combine(targetDirectory + "/obj", "ApplicationMain.ico")); - CPPHelper.compile(project, targetDirectory + "/obj", flags); + CPPHelper.compile(project, targetDirectory + "/obj", flags); - System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath); + System.copyFile(targetDirectory + "/obj/ApplicationMain" + (project.debug ? "-debug" : "") + ".exe", executablePath); - if (project.defines.exists("mingw")) + if (project.defines.exists("mingw")) + { + var libraries = ["libwinpthread-1.dll", "libstdc++-6.dll"]; + if (is64) { - var libraries = ["libwinpthread-1.dll", "libstdc++-6.dll"]; - if (is64) - { - libraries.push("libgcc_s_seh-1.dll"); - } - else - { - libraries.push("libgcc_s_dw2-1.dll"); - } + libraries.push("libgcc_s_seh-1.dll"); + } + else + { + libraries.push("libgcc_s_dw2-1.dll"); + } - for (library in libraries) - { - System.copyIfNewer(targetDirectory + "/obj/" + library, Path.combine(applicationDirectory, library)); - } + for (library in libraries) + { + System.copyIfNewer(targetDirectory + "/obj/" + library, Path.combine(applicationDirectory, library)); } } - else - { - System.runCommand("", "haxe", haxeArgs.concat(["-D", "static_link"])); + } + else + { + System.runCommand("", "haxe", haxeArgs.concat(["-D", "static_link"])); - if (noOutput) return; + if (noOutput) return; - IconHelper.createWindowsIcon(icons, Path.combine(targetDirectory + "/obj", "ApplicationMain.ico")); + IconHelper.createWindowsIcon(icons, Path.combine(targetDirectory + "/obj", "ApplicationMain.ico")); - CPPHelper.compile(project, targetDirectory + "/obj", flags.concat(["-Dstatic_link"])); + CPPHelper.compile(project, targetDirectory + "/obj", flags.concat(["-Dstatic_link"])); - CPPHelper.compile(project, targetDirectory + "/obj", flags, "BuildMain.xml"); + CPPHelper.compile(project, targetDirectory + "/obj", flags, "BuildMain.xml"); - System.copyFile(targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath); - } + System.copyFile(targetDirectory + "/obj/Main" + (project.debug ? "-debug" : "") + ".exe", executablePath); } } } @@ -661,66 +413,36 @@ class WindowsPlatform extends PlatformTarget { var context = project.templateContext; - if (targetType == "winjs") + if (targetType == "cpp") { - context.WIN_FLASHBACKGROUND = project.window.background != null ? StringTools.hex(project.window.background, 6) : ""; - context.OUTPUT_FILE = outputFile; - - if (project.targetFlags.exists("webgl")) - { - context.CPP_DIR = targetDirectory; - } - - var guid = GUID.seededUuid(project.meta.packageName); - context.APP_GUID = guid; - - var guidNoBrackets = guid.split("{").join("").split("}").join(""); - context.APP_GUID_NOBRACKETS = guidNoBrackets; - if (context.APP_DESCRIPTION == null || context.APP_DESCRIPTION == "") { context.APP_DESCRIPTION = project.meta.title; } - } - else if (targetType == "winrt") - { - context.CPP_DIR = targetDirectory + "/obj"; - context.BUILD_DIR = project.app.path + "/winrt" + (is64 ? "64" : ""); - context.DC = "::"; - } - else - { - if (targetType == "cpp") - { - if (context.APP_DESCRIPTION == null || context.APP_DESCRIPTION == "") - { - context.APP_DESCRIPTION = project.meta.title; - } - if (context.APP_COPYRIGHT_YEARS == null || context.APP_COPYRIGHT_YEARS == "") - { - context.APP_COPYRIGHT_YEARS = Std.string(Date.now().getFullYear()); - } + if (context.APP_COPYRIGHT_YEARS == null || context.APP_COPYRIGHT_YEARS == "") + { + context.APP_COPYRIGHT_YEARS = Std.string(Date.now().getFullYear()); + } - var versionParts = project.meta.version.split("."); + var versionParts = project.meta.version.split("."); - if (versionParts.length == 3) - { - versionParts.push("0"); - } - - context.FILE_VERSION = versionParts.join("."); - context.VERSION_NUMBER = versionParts.join(","); + if (versionParts.length == 3) + { + versionParts.push("0"); } - context.NEKO_FILE = targetDirectory + "/obj/ApplicationMain.n"; - context.NODE_FILE = targetDirectory + "/bin/ApplicationMain.js"; - context.HL_FILE = targetDirectory + "/obj/ApplicationMain" + (project.defines.exists("hlc") ? ".c" : ".hl"); - context.CPPIA_FILE = targetDirectory + "/obj/ApplicationMain.cppia"; - context.CPP_DIR = targetDirectory + "/obj"; - context.BUILD_DIR = project.app.path + "/windows" + (is64 ? "64" : ""); + context.FILE_VERSION = versionParts.join("."); + context.VERSION_NUMBER = versionParts.join(","); } + context.NEKO_FILE = targetDirectory + "/obj/ApplicationMain.n"; + context.NODE_FILE = targetDirectory + "/bin/ApplicationMain.js"; + context.HL_FILE = targetDirectory + "/obj/ApplicationMain" + (project.defines.exists("hlc") ? ".c" : ".hl"); + context.CPPIA_FILE = targetDirectory + "/obj/ApplicationMain.cppia"; + context.CPP_DIR = targetDirectory + "/obj"; + context.BUILD_DIR = project.app.path + "/windows" + (is64 ? "64" : ""); + return context; } @@ -746,14 +468,8 @@ class WindowsPlatform extends PlatformTarget { case "hl": hxml.hl = "_.hl"; - case "neko": - hxml.neko = "_.n"; case "cppia": hxml.cppia = "_.cppia"; - case "java": - hxml.java = "_"; - case "nodejs", "winjs": - hxml.js = "_.js"; default: hxml.cpp = "_"; } @@ -764,70 +480,50 @@ class WindowsPlatform extends PlatformTarget public override function rebuild():Void { - if (targetType != "winjs") - { - // if (project.environment.exists ("VS110COMNTOOLS") && project.environment.exists ("VS100COMNTOOLS")) { + // if (project.environment.exists ("VS110COMNTOOLS") && project.environment.exists ("VS100COMNTOOLS")) { - // project.environment.set ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS")); - // Sys.putEnv ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS")); + // project.environment.set ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS")); + // Sys.putEnv ("HXCPP_MSVC", project.environment.get ("VS100COMNTOOLS")); - // } + // } - var commands = []; - if (targetType == "hl") + var commands = []; + if (targetType == "hl") + { + // default to 64 bit, just like upstream Hashlink releases + if (!targetFlags.exists("32") && !targetFlags.exists("x86_32") + && (System.hostArchitecture == X64 || targetFlags.exists("64") || targetFlags.exists("x86_64"))) { - // default to 64 bit, just like upstream Hashlink releases - if (!targetFlags.exists("32") && !targetFlags.exists("x86_32") - && (System.hostArchitecture == X64 || targetFlags.exists("64") || targetFlags.exists("x86_64"))) - { - commands.push(["-Dwindows", "-DHXCPP_M64", "-Dhashlink"]); - } - else - { - commands.push(["-Dwindows", "-DHXCPP_M32", "-Dhashlink"]); - } + commands.push(["-Dwindows", "-DHXCPP_M64", "-Dhashlink"]); } else { - if (!targetFlags.exists("64") && !targetFlags.exists("x86_64") - && (command == "rebuild" || System.hostArchitecture == X86 || (targetType != "cpp" && targetType != "winrt"))) - { - if (targetType == "winrt") - { - commands.push(["-Dwinrt", "-DHXCPP_M32"]); - } - else - { - commands.push(["-Dwindows", "-DHXCPP_M32"]); - } - } - - // TODO: Compiling with -Dfulldebug overwrites the same "-debug.pdb" - // as previous Windows builds. For now, force -64 to be done last - // so that it can be debugged in a default "rebuild" - - if (!targetFlags.exists("32") && !targetFlags.exists("x86_32") - && System.hostArchitecture == X64 - && (command != "rebuild" || targetType == "cpp" || targetType == "winrt")) - { - if (targetType == "winrt") - { - commands.push(["-Dwinrt", "-DHXCPP_M64"]); - } - else - { - commands.push(["-Dwindows", "-DHXCPP_M64"]); - } - } + commands.push(["-Dwindows", "-DHXCPP_M32", "-Dhashlink"]); + } + } + else + { + if (!targetFlags.exists("64") && !targetFlags.exists("x86_64") && (command == "rebuild" || System.hostArchitecture == X86 || targetType != "cpp")) + { + commands.push(["-Dwindows", "-DHXCPP_M32"]); } - if (targetFlags.exists("hl")) + // TODO: Compiling with -Dfulldebug overwrites the same "-debug.pdb" + // as previous Windows builds. For now, force -64 to be done last + // so that it can be debugged in a default "rebuild" + + if (!targetFlags.exists("32") && !targetFlags.exists("x86_32") && System.hostArchitecture == X64 && (command != "rebuild" || targetType == "cpp")) { - CPPHelper.rebuild(project, commands, null, "BuildHashlink.xml"); + commands.push(["-Dwindows", "-DHXCPP_M64"]); } + } - CPPHelper.rebuild(project, commands); + if (targetFlags.exists("hl")) + { + CPPHelper.rebuild(project, commands, null, "BuildHashlink.xml"); } + + CPPHelper.rebuild(project, commands); } public override function run():Void @@ -839,98 +535,12 @@ class WindowsPlatform extends PlatformTarget arguments.push("-verbose"); } - if (targetType == "nodejs") - { - NodeJSHelper.run(project, targetDirectory + "/bin/ApplicationMain.js", arguments); - } - else if (targetType == "cppia") + if (targetType == "cppia") { // arguments = arguments.concat(["-livereload"]); arguments = ["script.cppia"]; // .concat(arguments); System.runCommand(applicationDirectory, Path.withoutDirectory(executablePath), arguments); } - else if (targetType == "winjs") - { - /* - - The 'test' target is problematic for UWP applications. UWP applications are bundled in appx packages and - require app certs to properly install. - - There are two options to trigger an appx install from the command line. - - A. Use the WinAppDeployCmd.exe utility to deploy to local and remote devices - - B. Execute the Add-AppDevPackage.ps1 powershell script that is an - artifact of the UWP msbuild - - A: WinAppDeployCmd.exe - https://docs.microsoft.com/en-us/windows/uwp/packaging/install-universal-windows-apps-with-the-winappdeploycmd-tool - https://msdn.microsoft.com/en-us/windows/desktop/mt627714 - Windows 10 SDK: https://developer.microsoft.com/windows/downloads/windows-10-sdk - - I've never actually got this to work, but I feel like I was close. The WinAppDeployCmd.exe is a part of the - Windows 10 SDK and not a part of the Visual Studio 2017 community edition. It will appear magically if you - check enough boxes when installing various project templates for Visual Studio. It appeared for me, and I - have no clue how it got there. - - A developer must take a few steps in order for this command to work. - 1. Install Visual Studio 2017 Community Edition - 2. Install the Windows 10 SDK - 3. Modify Windows 10 Settings to enable side loading and device discovery - 3. Enabling device discovery generates a pin number that is displayed to the user - 4. Open the "Developer Command Promp for VS 2017" from the Start menu - 5. run: - > WinAppDeployCmd devices - 6. Make sure your device shows up in the list (if it does not appear try step 3 again, toggling things on/off) - 7. run: (replase file, ip and pin with your values) - > WinAppDeployCmd install -file "uwp-project_1.0.0.0_AnyCPU.appx" -ip 192.168.27.167 -pin 326185 - - B: Add-AppDevPackage.ps1 + PowerShell_Set_Unrestricted.reg - The UWP build generates a powershell script by default. This script is usually executed by the user - by right clicking the file and choosing "run with powershell". Executing this script directly from the cmd - prompt results in a security error: "Add-AppDevPackage.ps1 cannot be loaded because running scripts is - disabled on this system." - - We must edit the registry if we want to run this script directly from a shell. - See lime/templates/windows/template/PowerShell_Set_Unrestricted.reg - - 1. run: - > regedit /s PowerShell_Set_Unrestricted.reg - 2. run: - > powershell "& ""./Add-AppDevPackage.ps1""" - - note: the nonsensical double quotes are required. - - */ - - // Using option B because obtaining the device pin programatically does not seem possible. - // System.runCommand ("", "regedit", [ '/s', '"' + targetDirectory + '/bin/PowerShell_Set_Unrestricted.reg"' ]); - // var test = '"& ""' + targetDirectory + '/bin/PowerShell_Set_Unrestricted.reg"""'; - // Sys.command ('powershell & ""' + targetDirectory + '/bin/source/AppPackages/' + project.app.file + '_1.0.0.0_AnyCPU_Test/Add-AppDevPackage.ps1""'); - var version = project.meta.version + "." + project.meta.buildNumber; - System.openFile(targetDirectory - + "/source/AppPackages/" - + project.app.file - + "_" - + version - + "_AnyCPU_Test", - project.app.file - + "_" - + version - + "_AnyCPU.appx"); - - // source/AppPackages/uwp-project_1.0.0.0_AnyCPU_Test/Add-AppDevPackage.ps1 - - // HTML5Helper.launch (project, targetDirectory + "/bin"); - } - else if (targetType == "java") - { - System.runCommand(applicationDirectory, "java", ["-jar", project.app.file + ".jar"].concat(arguments)); - } - else if (targetType == "winrt") - { - winrtRun(arguments); - } else if (project.target == System.hostPlatform) { arguments = arguments.concat(["-livereload"]); @@ -942,12 +552,6 @@ class WindowsPlatform extends PlatformTarget { AssetHelper.processLibraries(project, targetDirectory); - if (targetType == "winjs") - { - updateUWP(); - return; - } - // project = project.clone (); if (project.targetFlags.exists("xml")) @@ -969,7 +573,7 @@ class WindowsPlatform extends PlatformTarget var context = generateContext(); context.OUTPUT_DIR = targetDirectory; - if ((targetType == "cpp" || targetType == "winrt") && project.targetFlags.exists("static")) + if (targetType == "cpp" && project.targetFlags.exists("static")) { var programFiles = project.environment.get("ProgramFiles(x86)"); var hasVSCommunity = (programFiles != null @@ -992,8 +596,7 @@ class WindowsPlatform extends PlatformTarget if (ndll.path == null || ndll.path == "") { - context.ndlls[i].path = NDLL.getLibraryPath(ndll, (targetType == "winrt" ? "WinRT" : "Windows") + (is64 ? "64" : ""), "lib", suffix, - project.debug); + context.ndlls[i].path = NDLL.getLibraryPath(ndll, "Windows" + (is64 ? "64" : ""), "lib", suffix, project.debug); } } } @@ -1008,15 +611,7 @@ class WindowsPlatform extends PlatformTarget ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context); ProjectHelper.recursiveSmartCopyTemplate(project, targetType + "/hxml", targetDirectory + "/haxe", context); - if (targetType == "winrt" && project.targetFlags.exists("static")) - { - ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/assetspkg", targetDirectory + "/bin/assetspkg", context, false, true); - ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/appx", targetDirectory + "/bin", context, true, true); - ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/static", targetDirectory + "/obj", context, true, true); - ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/temp", targetDirectory + "/haxe/temp", context, false, true); - ProjectHelper.recursiveSmartCopyTemplate(project, "winrt/scripts", targetDirectory + "/scripts", context, true, true); - } - else if (targetType == "cpp") + if (targetType == "cpp") { ProjectHelper.recursiveSmartCopyTemplate(project, "windows/resource", targetDirectory + "/obj", context); @@ -1053,204 +648,6 @@ class WindowsPlatform extends PlatformTarget } } - private function updateUWP():Void - { - project = project.clone(); - - var destination = targetDirectory + "/source/"; - System.mkdir(destination); - - var webfontDirectory = targetDirectory + "/obj/webfont"; - var useWebfonts = true; - - for (haxelib in project.haxelibs) - { - if (haxelib.name == "openfl-html5-dom" || haxelib.name == "openfl-bitfive") - { - useWebfonts = false; - } - } - - var fontPath; - - for (asset in project.assets) - { - if (asset.type == AssetType.FONT) - { - if (useWebfonts) - { - fontPath = Path.combine(webfontDirectory, Path.withoutDirectory(asset.targetPath)); - - if (!FileSystem.exists(fontPath)) - { - System.mkdir(webfontDirectory); - System.copyFile(asset.sourcePath, fontPath); - - asset.sourcePath = fontPath; - - HTML5Helper.generateWebfonts(project, asset); - } - - asset.sourcePath = fontPath; - asset.targetPath = Path.withoutExtension(asset.targetPath); - } - else - { - // project.haxeflags.push (HTML5Helper.generateFontData (project, asset)); - } - } - } - - if (project.targetFlags.exists("xml")) - { - project.haxeflags.push("-xml " + targetDirectory + "/types.xml"); - } - - if (Log.verbose) - { - project.haxedefs.set("verbose", 1); - } - - ModuleHelper.updateProject(project); - - var libraryNames = new Map(); - - for (asset in project.assets) - { - if (asset.library != null && !libraryNames.exists(asset.library)) - { - libraryNames[asset.library] = true; - } - } - - // for (library in libraryNames.keys ()) { - // - // project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/" + library + ".json@__ASSET_MANIFEST__" + library); - // - // } - - // project.haxeflags.push ("-resource " + targetDirectory + "/obj/manifest/default.json@__ASSET_MANIFEST__default"); - - var context = generateContext(); - context.OUTPUT_DIR = targetDirectory; - - context.favicons = []; - - var icons = project.icons; - - if (icons.length == 0) - { - icons = [new Icon(System.findTemplate(project.templatePaths, "default/icon.svg"))]; - } - - // if (IconHelper.createWindowsIcon (icons, Path.combine (destination, "favicon.ico"))) { - // - // context.favicons.push ({ rel: "icon", type: "image/x-icon", href: "./favicon.ico" }); - // - // } - - if (IconHelper.createIcon(icons, 192, 192, Path.combine(destination, "favicon.png"))) - { - context.favicons.push({rel: "shortcut icon", type: "image/png", href: "./favicon.png"}); - } - - context.linkedLibraries = []; - - for (dependency in project.dependencies) - { - if (StringTools.endsWith(dependency.name, ".js")) - { - context.linkedLibraries.push(dependency.name); - } - else if (StringTools.endsWith(dependency.path, ".js") && FileSystem.exists(dependency.path)) - { - var name = Path.withoutDirectory(dependency.path); - - context.linkedLibraries.push("./js/lib/" + name); - copyIfNewer(dependency.path, Path.combine(destination, Path.combine("js/lib", name))); - } - } - - for (asset in project.assets) - { - var path = Path.combine(destination, asset.targetPath); - - if (asset.type != AssetType.TEMPLATE) - { - if (asset.type != AssetType.FONT) - { - System.mkdir(Path.directory(path)); - AssetHelper.copyAssetIfNewer(asset, path); - } - else if (useWebfonts) - { - System.mkdir(Path.directory(path)); - var ext = "." + Path.extension(asset.sourcePath); - var source = Path.withoutExtension(asset.sourcePath); - - for (extension in [ext, ".eot", ".woff", ".svg"]) - { - if (FileSystem.exists(source + extension)) - { - System.copyIfNewer(source + extension, path + extension); - } - else - { - Log.warn("Could not find generated font file \"" + source + extension + "\""); - } - } - } - } - } - - ProjectHelper.recursiveSmartCopyTemplate(project, "winjs/template", targetDirectory, context); - - var renamePaths = [ - "uwp-project.sln", - "source/uwp-project.jsproj", - "source/uwp-project_TemporaryKey.pfx" - ]; - var fullPath; - - for (path in renamePaths) - { - fullPath = targetDirectory + "/" + path; - - try - { - if (FileSystem.exists(fullPath)) - { - File.copy(fullPath, targetDirectory + "/" + StringTools.replace(path, "uwp-project", project.app.file)); - FileSystem.deleteFile(fullPath); - } - } - catch (e:Dynamic) {} - } - - if (project.app.main != null) - { - ProjectHelper.recursiveSmartCopyTemplate(project, "haxe", targetDirectory + "/haxe", context); - ProjectHelper.recursiveSmartCopyTemplate(project, "winjs/haxe", targetDirectory + "/haxe", context, true, false); - ProjectHelper.recursiveSmartCopyTemplate(project, "winjs/hxml", targetDirectory + "/haxe", context); - - if (project.targetFlags.exists("webgl")) - { - ProjectHelper.recursiveSmartCopyTemplate(project, "webgl/hxml", targetDirectory + "/haxe", context, true, false); - } - } - - for (asset in project.assets) - { - var path = Path.combine(destination, asset.targetPath); - - if (asset.type == AssetType.TEMPLATE) - { - System.mkdir(Path.directory(path)); - AssetHelper.copyAsset(asset, path, context); - } - } - } - public override function watch():Void { var hxml = getDisplayHXML(); @@ -1266,315 +663,9 @@ class WindowsPlatform extends PlatformTarget System.watch(command, dirs); } - // @ignore public override function install ():Void {} - override public function install():Void - { - super.install(); - if (targetType == "winrt") - { - if (project.targetFlags.exists("appx")) - { - var context = project.templateContext; - buildWinrtPackage(context.KEY_STORE, context.KEY_STORE_PASSWORD); - } - else - { - uninstall(); - Log.info("run: Register app"); - var process = new sys.io.Process('powershell', [ - "-noprofile", - "-command", - 'Add-AppxPackage -Path ' + applicationDirectory + "/" + 'AppxManifest.xml -Register' - ]); - if (process.exitCode() != 0) - { - var message = process.stderr.readAll().toString(); - Log.error("Cannot register. " + message); - } - process.close(); - } - } - } + @ignore public override function install ():Void {} @ignore public override function trace():Void {} - // @ignore public override function uninstall ():Void {} - override public function uninstall():Void - { - super.uninstall(); - if (targetType == "winrt" && !project.targetFlags.exists("appx")) - { - var appxName = project.meta.packageName; - Log.info("run: Remove previous registered app"); - var process = new sys.io.Process('powershell', [ - "-noprofile", - "-command", - 'Get-AppxPackage ' + appxName + ' | Remove-AppxPackage' - ]); - if (process.exitCode() != 0) - { - var message = process.stderr.readAll().toString(); - Log.error("Cannot remove. " + message); - } - process.close(); - } - // TODO if (targetType == "winrt" && project.targetFlags.exists("appx")) - } - - public function winrtRun(arguments:Array):Void - { - var dir = applicationDirectory; - var haxeDir = targetDirectory + "/haxe"; - if (project.targetFlags.exists("appx")) - { - Log.info("\n***Double click on " + project.app.file + ".Appx to install Appx"); - } - else - { - var appxName = project.meta.packageName; - var appxId = "App"; - var appxAUMID:String = null; - var appxInfoFile = haxeDir + "/appxinfo.txt"; - var kitsRoot10 = "C:\\Program Files (x86)\\Windows Kits\\10\\"; // %WindowsSdkDir% - - // get PackageFamilyappxName and set appxAUMID - // write app info in a file - var cmd = 'Get-AppxPackage ' + appxName + ' | Out-File ' + appxInfoFile + ' -Encoding ASCII'; - Log.info("powershell " + cmd); - var process3 = new sys.io.Process('powershell', [cmd]); - if (process3.exitCode() != 0) - { - var message = process3.stderr.readAll().toString(); - Log.error("Cannot get PackageFamilyName. " + message); - } - process3.close(); - // parse file - if (sys.FileSystem.exists(appxInfoFile)) - { - var fin = sys.io.File.read(appxInfoFile, false); - try - { - while (true) - { - var str = fin.readLine(); - var split = str.split(":"); - var name = StringTools.trim(split[0]); - if (name == "PackageFamilyName") - { - var appxPackageFamilyName = StringTools.trim(split[1]); - if (appxPackageFamilyName != null) - { - appxAUMID = appxPackageFamilyName + "!" + appxId; - break; - } - } - } - } - catch (e:haxe.io.Eof) - { - Log.error('Could not get PackageFamilyName from ' + appxInfoFile); - } - fin.close(); - } - - Log.info("run: " + appxAUMID); - Log.info(kitsRoot10 + 'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe ' + appxAUMID); - var process4 = new sys.io.Process(kitsRoot10 + 'App Certification Kit\\microsoft.windows.softwarelogo.appxlauncher.exe', [appxAUMID]); - } - } - - public function buildWinrtPackage(pfxPath:String, certificatePwd:String):Void - { - if (project.targetFlags.exists("appx")) - { - var kitsRoot10 = "C:\\Program Files (x86)\\Windows Kits\\10\\"; // %WindowsSdkDir% - var haxeDir = targetDirectory + "/haxe"; - - var binDir:String = kitsRoot10 + "\\bin"; - if (sys.FileSystem.exists(binDir)) - { - var maxSDK:Int = 0; - for (file in sys.FileSystem.readDirectory(binDir)) - { - if (StringTools.startsWith(file, "10.0")) - { - var file2 = file.split("10.0.")[1]; - file2 = file2.split(".0")[0]; - var fileSDK:Int = Std.parseInt(file2); - maxSDK = (maxSDK > fileSDK ? maxSDK : fileSDK); - } - } - if (maxSDK > 0) - { - Log.info("Found max SDK 10.0." + maxSDK + ".0"); - binDir += "\\10.0." + maxSDK + ".0"; - } - } - else - { - Log.error('"$binDir" does not exists'); - return; - } - - var makepriPath = binDir + '\\x86\\MakePri.exe'; - var makeappxPath = binDir + '\\x86\\MakeAppx.exe'; - var signToolPath = binDir + '\\x64\\SignTool.exe'; - - var resultFilePath = haxeDir + "\\temp"; - var resultFileName = resultFilePath + "/layout.resfiles"; - Log.info("make pri"); - - var outputDirectory = Path.combine(FileSystem.fullPath(targetDirectory), "appx"); - var binPath = Path.combine(FileSystem.fullPath(targetDirectory), "bin"); - - pfxPath = Path.combine(outputDirectory, pfxPath); - // prepare file to make pri - try - { - var from = outputDirectory; - var buf = new StringBuf(); - - // todo - var outputFiles = FileSystem.readDirectory(binPath); - - for (filename in outputFiles) - { - if (!(StringTools.endsWith(filename, ".exe") || StringTools.endsWith(filename, ".pri")) - && filename != "AppxManifest.xml") - { - buf.add(filename); - buf.addChar(10); - } - } - - if (sys.FileSystem.exists(resultFileName)) sys.FileSystem.deleteFile(sys.FileSystem.absolutePath(resultFileName)); - - sys.io.File.saveContent(resultFileName, buf.toString()); - Log.info("Created layout.resfiles : " + resultFileName); - } - catch (e:Dynamic) - { - Log.error("Error creating layout.resfiles " + e); - } - - var makepriParams = [ - "new", - "/ProjectRoot", - resultFilePath, - "/ConfigXml", - resultFilePath + "\\priconfig.xml", - "/Manifest", - applicationDirectory + "/" + 'AppxManifest.xml', - "/OutputFile", - applicationDirectory + "resources.pri" - ]; - Log.info(makepriPath + " " + makepriParams); - var process = new sys.io.Process(makepriPath, makepriParams); - - // needs to wait make pri - var retry:Int = 10; - while (retry > 0 && !sys.FileSystem.exists(applicationDirectory + "/" + "resources.pri")) - { - Sys.sleep(1); - Log.info("waiting pri.."); - retry--; - } - if (retry <= 0) Log.error("Error on MakePri"); - - var appxDir = applicationDirectory + "../"; - - Log.info("make " + project.app.file + ".Appx"); - var makeappParams = ["pack", "/d", applicationDirectory, "/p", appxDir + project.app.file + ".Appx"]; - var process2 = new sys.io.Process(makeappxPath, makeappParams); - Log.info(makeappParams.toString()); - process.close(); - process2.close(); - - var pfxFileName = project.app.file + ".pfx"; - - if (pfxPath != null && pfxPath.length > 0) - { - if (sys.FileSystem.exists(appxDir + "scripts/" + pfxFileName)) - { - // apply certificate - Log.info("Pfx cert found: path: " + appxDir + "scripts/" + pfxFileName + ", pwd:" + certificatePwd); - } - else - { - // create certificate - Log.warn("Warn: certificate " + pfxPath + " not found, run the following command to create a new one:"); - // copyTemplateDir( "winrt/scripts", applicationDirectory+"/.." ); - - // New certificate, calls powershell script on elevated mode - // var cmd = "Start-Process powershell \"-ExecutionPolicy Bypass -Command `\"cd `\""+sys.FileSystem.absolutePath(applicationDirectory)+"/.."+"`\"; & `\".\\newcertificate.ps1`\"`\"\" -Verb RunAs"; - // var cmd = "Start-Process powershell \"-Command `\"cd `\""+sys.FileSystem.absolutePath(applicationDirectory)+"/.."+"`\"; & `\".\\newcertificate.ps1`\"`\"\" -Verb RunAs"; - - // var cmd = "\"cd "+sys.FileSystem.absolutePath(applicationDirectory)+"/../scripts;Start-Process powershell -verb runas -ArgumentList \'-file .\\newcertificate.ps1\'\""; - - var cmd = "-Command \"Start-Process powershell \\\"-ExecutionPolicy Bypass -NoProfile -NoExit -Command `\\\"cd \\`\\\"E:/openfl/BunnyMark/Export/winrt/bin/../scripts\\`\\\"; & \\`\\\".\\newcertificate.ps1\\`\\\"`\\\"\\\" -Verb RunAs\""; - Log.info("powershell " + cmd); - - #if 0 - var process3 = new sys.io.Process("powershell", [cmd]); - if (process3.exitCode() != 0) - { - var message = process3.stderr.readAll().toString(); - Log.error("Error newcertificate. " + message); - } - process3.close(); - - // check pfx - retry = 10; - while (retry > 0 && !sys.FileSystem.exists(appxDir + "scripts/" + pfxFileName)) - { - Log.info("waiting " + appxDir + "scripts/" + pfxFileName); - Sys.sleep(6); - retry--; - } - if (retry <= 0) Log.error("Error creating certificate"); - #else - return; - #end - } - - if (appxDir + "scripts/" + pfxFileName != pfxPath) - { - System.copyFile(appxDir + "scripts/" + pfxFileName, pfxPath); - if (!sys.FileSystem.exists(pfxPath)) - { - Log.error("could not copy " + appxDir + pfxFileName + " to " + pfxPath); - } - } - } - - if (pfxPath != null && certificatePwd != null && pfxPath.length > 0 && certificatePwd.length > 0) - { - Log.info("signing " + project.app.file + ".Appx with " + pfxPath); - - var signParams = [ - "sign", - "/fd", - "SHA256", - "/a", - "/f", - pfxPath, - "/p", - certificatePwd, - appxDir + project.app.file + ".Appx" - ]; - - Log.info(signToolPath + " " + signParams); - var process4 = new sys.io.Process(signToolPath, signParams); - if (process4.exitCode() != 0) - { - var message = process4.stderr.readAll().toString(); - Log.error("Error signing appx. " + message); - } - Log.info("\n\n***Double click " - + pfxPath - + " to setup certificate (Local machine, Place all certificates in the following store->Trusted People)\n"); - process4.close(); - } - } - } + @ignore public override function uninstall ():Void {} } diff --git a/tools/utils/JavaExternGenerator.hx b/tools/utils/JavaExternGenerator.hx deleted file mode 100644 index 5213e7f35e..0000000000 --- a/tools/utils/JavaExternGenerator.hx +++ /dev/null @@ -1,862 +0,0 @@ -package utils; - -import haxe.crypto.BaseCode; -import haxe.io.Bytes; -import haxe.io.Input; -import haxe.io.Output; -import haxe.zip.Compress; -import haxe.zip.Reader; -import hxp.*; -import lime.tools.HXProject; -import sys.io.File; -import sys.io.Process; -import sys.FileSystem; - -class JavaExternGenerator -{ - private static inline var ACC_PUBLIC = 0x0001; - private static inline var ACC_PRIVATE = 0x0002; - private static inline var ACC_PROTECTED = 0x0004; - private static inline var ACC_STATIC = 0x0008; - private static inline var ACC_FINAL = 0x0010; - private static inline var ACC_SUPER = 0x0020; - private static inline var ACC_INTERFACE = 0x0200; - private static inline var ACC_ABSTRACT = 0x0400; - private static inline var dollars = "___"; - private static var base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - private static var fmatch = ~/^\((.*)\)(.*)/; - - private var config:HXProject; - private var externPath:String; - private var extractedAndroidClasses:Bool; - private var extractedAndroidPaths:Array; - private var javaPath:String; - private var mConstants:Array; - private var mProcessed:Map; - private var mStack:Array; - private var mOutput:Output; - private var mCurrentType:String; - private var mExactTypes:Map; - private var parsedTypes:Array; - private var parsedIsObj:Array; - private var retType:JNIType; - - public function new(config:HXProject, javaPath:String, externPath:String) - { - this.config = config; - this.javaPath = javaPath; - this.externPath = externPath; - - mProcessed = new Map(); - mExactTypes = new Map(); - mProcessed.set("java/lang/Object", true); - - var paths = new Array(); - - if (FileSystem.isDirectory(javaPath)) - { - this.javaPath += "/"; - getPaths(javaPath, "", paths); - } - else - { - var path = Path.withoutExtension(javaPath); - - if (Path.extension(javaPath) == "jar") - { - this.javaPath = path + "/"; - System.mkdir(path); - System.runCommand(path, "jar", ["-xvf", FileSystem.fullPath(javaPath)], false); - getPaths(path, "", paths); - } - else - { - this.javaPath = ""; - paths = [path]; - } - } - - for (path in paths) - { - var type = Path.withoutExtension(path); - mProcessed.set(type, true); - mExactTypes.set(type, true); - } - - mStack = paths; - - while (mStack.length > 0) - { - var clazz = mStack.pop(); - var members = new Map(); - generate(clazz, members); - } - - for (path in extractedAndroidPaths) - { - if (FileSystem.exists(path)) - { - removeRecursive(path); - } - } - } - - private function addType(inName:String, inJavaType:String, inArrayCount:Int) - { - parsedTypes.push({name: inName, java: inJavaType, arrayCount: inArrayCount}); - } - - private static function debug(s:String) {} - - private function extractAndroidClasses() - { - if (!extractedAndroidClasses) - { - extractedAndroidPaths = []; - var platformsDirectory = config.environment.get("ANDROID_SDK") + "/platforms"; - - if (FileSystem.exists(platformsDirectory)) - { - for (path in FileSystem.readDirectory(platformsDirectory)) - { - var directory = platformsDirectory + "/" + path; - - if (path.indexOf("android-") > -1 && FileSystem.isDirectory(directory)) - { - var androidJAR = directory + "/android.jar"; - - if (FileSystem.exists(androidJAR)) - { - System.mkdir(path); - extractedAndroidPaths.push(path); - System.runCommand(path, "jar", ["-xvf", androidJAR], false); - } - } - } - } - else - { - throw "Could not find Android SDK directory. Check that ANDROID_SDK is defined in ~/.lime/config.xml"; - } - } - extractedAndroidClasses = true; - } - - private function generate(inClass:String, inMembers:Map) - { - Sys.println(inClass); - - var parts = Path.withoutExtension(inClass).split("/"); - var old_type = mCurrentType; - mCurrentType = parts.join("."); - mExactTypes.set(mCurrentType, true); - var dir_parts = parts.slice(0, parts.length - 1); - var outputBase = externPath; - var dir = outputBase; - System.mkdir(dir); - - for (d in dir_parts) - { - dir += "/" + d; - System.mkdir(dir); - } - - var filename = javaPath + inClass + ".class"; - - if (!FileSystem.exists(filename)) - { - extractAndroidClasses(); - var foundFile = false; - - for (path in extractedAndroidPaths) - { - if (!foundFile) - { - filename = path + "/" + inClass + ".class"; - - if (FileSystem.exists(filename)) - { - foundFile = true; - } - } - } - - if (!foundFile) - { - throw "Could not find class file: \"" + inClass + "\""; - } - } - - var source = File.read(filename, true); - var class_name = parts[parts.length - 1].split("$").join(dollars); - var old_output = mOutput; - mOutput = File.write(dir + "/" + class_name + ".hx", true); - var old_constants = mConstants; - mConstants = new Array(); - - parse(source, inMembers); - - source.close(); - mOutput.close(); - mOutput = old_output; - mCurrentType = old_type; - mConstants = old_constants; - } - - public static function getHaxelib(library:String):String - { - var proc = new Process("haxelib", ["path", library]); - var result = ""; - - try - { - while (true) - { - var line = proc.stdout.readLine(); - if (line.substr(0, 1) != "-") result = line; - } - } - catch (e:Dynamic) {}; - proc.close(); - if (result == "") throw("Could not find haxelib path " + library + " - perhaps you need to install it?"); - - return result; - } - - private function getPaths(basePath:String, source:String, paths:Array) - { - var files = FileSystem.readDirectory(basePath + "/" + source); - - for (file in files) - { - if (file.substr(0, 1) != ".") - { - var itemSource:String = source + "/" + file; - - if (source == "") - { - itemSource = file; - } - - if (FileSystem.isDirectory(basePath + "/" + itemSource)) - { - getPaths(basePath, itemSource, paths); - } - else - { - if (Path.extension(itemSource) == "class") - { - paths.push(Path.withoutExtension(itemSource)); - } - } - } - } - } - - private function isJavaObject(inType) - { - if (inType.arrayCount > 0) return false; - return switch (inType.name) - { - case "Int", "Void", "Bool", "Float": false; - default: true; - } - } - - private function isPOD(inName:String) - { - switch (inName) - { - case "Int", "Void", "Bool", "Float", "String": - return true; - } - return false; - } - - private function javaType(inType) - { - var result = inType.java; - result = StringTools.replace(result, "/", "."); - for (i in 0...inType.arrayCount) - result += "[]"; - return result; - } - - private function mkdir(inName:String) - { - if (!FileSystem.exists(inName)) FileSystem.createDirectory(inName); - } - - private function nmeCallType(inType) - { - if (isJavaObject(inType)) return "callObjectFunction"; - return "callNumericFunction"; - } - - private function output(str:String) - { - mOutput.writeString(str); - } - - private function outputClass(cid:Int, lastOnly:Bool) - { - var name:String = mConstants[mConstants[cid]]; - // pushClass(name); - name = name.split("$").join(dollars); - var parts = name.split("/"); - if (lastOnly) output(parts.pop()); - else - output(parts.join(".")); - } - - private function outputFunctionArgs() - { - output("("); - for (i in 0...parsedTypes.length) - { - if (i > 0) output(", "); - output("arg" + i + ":"); - outputType(parsedTypes[i]); - } - output(")"); - } - - private function outputPackage(cid:Int) - { - var name = (mConstants[mConstants[cid]]); - var parts = name.split("/"); - parts.pop(); - output("package " + parts.join(".") + ";\n\n\n"); - } - - private function outputType(inType:JNIType) - { - for (i in 0...inType.arrayCount) - output("Array<"); - output(inType.name); - for (i in 0...inType.arrayCount) - output(">"); - } - - private function parse(src:Input, inMembers:Map) - { - src.bigEndian = true; - - var m0 = src.readByte(); - var m1 = src.readByte(); - var m2 = src.readByte(); - var m3 = src.readByte(); - - debug(StringTools.hex(m0, 2) + StringTools.hex(m1, 2) + StringTools.hex(m2, 2) + StringTools.hex(m3, 2)); - debug("Version (min):" + src.readUInt16()); - debug("Version (maj):" + StringTools.hex(src.readUInt16(), 4)); - - var ccount = src.readUInt16(); - - debug("mConstants : " + ccount); - - var cid = 1; - while (cid < ccount) - { - var tag = src.readByte(); - switch (tag) - { - case 1: - var len = src.readUInt16(); - var str = src.readString(len); - // debug("Str:"+str); - mConstants[cid] = str; - - case 3: - var i = src.readInt32(); - // debug("Int32:"+i); - mConstants[cid] = i; - - case 4: - var f = src.readFloat(); - // debug("Float32:"+f); - mConstants[cid] = f; - - case 5: - var hi = src.readInt32(); - var lo = src.readInt32(); - // debug("Long - ignore"); - mConstants[cid] = {lo: lo, hi: hi}; - cid++; - - case 6: - var f = src.readDouble(); - // debug("Float64:"+f); - mConstants[cid] = f; - cid++; - - case 7: - var cref = src.readUInt16(); - // debug("Class ref:" + cref); - mConstants[cid] = cref; - - case 8: - var sref = src.readUInt16(); - // debug("String ref:" + sref); - mConstants[cid] = sref; - - case 9, 10, 11, 12: - var cref = src.readUInt16(); - var type = src.readUInt16(); - // debug("Member ref:" + cref + "," + type); - mConstants[cid] = {cref: cref, type: type}; - - default: - throw("Unknown constant tag:" + tag); - } - cid++; - } - - var access = src.readUInt16(); - - debug("Access: " + access); - - var is_interface = (access & ACC_INTERFACE) > 0; - var java_out:Output = null; - - var this_ref = src.readUInt16(); - - debug("This : " + mConstants[mConstants[this_ref]]); - - outputPackage(this_ref); - output("class "); - outputClass(this_ref, true); - - var super_ref = src.readUInt16(); - if (super_ref > 0) - { - debug("Super : " + mConstants[mConstants[super_ref]]); - - var name = mConstants[mConstants[super_ref]]; - if (name == "java/lang/Object") - { - debug(" -> ignore super"); - super_ref = 0; - } - else - { - output(" extends "); - outputClass(super_ref, false); - } - } - else - debug("Super : None."); - - if (super_ref > 0) generate(mConstants[mConstants[super_ref]], inMembers); - - var intf_count = src.readUInt16(); - - debug("Interfaces:" + intf_count); - - for (i in 0...intf_count) - { - var i_ref = src.readUInt16(); - /* - No need to expose these to haxe? - if (i>0 || super_ref>0) - output(","); - output(" implements "); - outputClass(i_ref,false); - debug("Implements : " + mConstants[mConstants[i_ref]]); - */ - } - - output("\n{\n"); - - if (super_ref == 0) output(" var __jobject:Dynamic;\n \n"); - - var java_name = ""; - - if (is_interface) - { - var dir = "stubs"; - var parts = mCurrentType.split("."); - var dir_parts = parts.slice(0, parts.length - 1); - System.mkdir(dir); - - for (d in dir_parts) - { - dir += "/" + d; - System.mkdir(dir); - } - - var interface_name = parts[parts.length - 1]; - var impl_name = "Haxe" + parts[parts.length - 1].split("$").join(""); - java_name = dir_parts.join("/") + "/" + impl_name + ".java"; - - java_out = File.write("stubs/" + java_name, true); - java_out.writeString("package " + dir_parts.join(".") + ";\n"); - java_out.writeString("import org.haxe.lime.Value;\n"); - java_out.writeString("import org.haxe.lime.Lime;\n\n"); - java_out.writeString("import " + StringTools.replace(parts.join("."), "$", ".") + ";\n\n"); - java_out.writeString("class " + impl_name + " implements " + interface_name.split("$").join(".") + " {\n"); - java_out.writeString(" long __haxeHandle;\n"); - java_out.writeString(" public " + impl_name + "(long inHandle) { __haxeHandle=inHandle; }\n"); - - output(" public function new() { __jobject = openfl.utils.JNI.createInterface(this,\"" - + dir_parts.join(".") - + "." - + impl_name - + "\", classDef ); }\n \n"); - } - - var field_count = src.readUInt16(); - - debug("Fields:" + field_count); - - var seen = new Map(); - - for (i in 0...field_count) - { - var access = src.readUInt16(); - var name_ref = src.readUInt16(); - - debug(" field : " + mConstants[name_ref]); - - var desc_ref = src.readUInt16(); - - debug(" desc : " + mConstants[desc_ref]); - - var expose = access == (ACC_PUBLIC | ACC_FINAL | ACC_STATIC); - var as_string = false; - - if (expose) - { - var type = toHaxeType(mConstants[desc_ref]).name; - if (isPOD(type)) - { - output(" static inline public var " + mConstants[name_ref] + ":" + type); - as_string = type == "String"; - } - else - expose = false; - } - - var att_count = src.readUInt16(); - - for (a in 0...att_count) - { - readAttribute(src, expose, as_string); - } - - if (expose) output(";\n"); - } - - var method_count = src.readUInt16(); - debug("Method:" + method_count); - - output(" \n"); - var constructed = false; - - for (i in 0...method_count) - { - var access = src.readUInt16(); - var expose = (access & ACC_PUBLIC) > 0; - var is_static = (access & ACC_STATIC) > 0; - var name_ref = src.readUInt16(); - debug(" method: " + mConstants[name_ref]); - var desc_ref = src.readUInt16(); - - var func_name = mConstants[name_ref]; - var constructor = func_name == ""; - - if (expose) - { - debug(" desc : " + mConstants[desc_ref]); - splitFunctionType(mConstants[desc_ref]); - - var func_key = func_name + " " + mConstants[desc_ref]; - if (constructor) - { - func_name = "_create"; - } - - // Method overloading ... - var uniq_name = func_name; - var do_override = ""; - if (inMembers.exists(func_key)) - { - uniq_name = inMembers.get(func_key); - if (!constructor && !is_static) do_override = "override "; - seen.set(uniq_name, true); - } - else - { - if (seen.exists(func_name)) - { - for (i in 1...100000) - { - uniq_name = func_name + i; - if (!seen.exists(uniq_name)) break; - } - } - seen.set(uniq_name, true); - inMembers.set(func_key, uniq_name); - } - - if (constructor) is_static = true; - - var ret_full_class = constructor || ((mExactTypes.exists(retType.name) || isPOD(retType.name)) && retType.arrayCount == 0); - - if (constructor) retType = {name: mCurrentType, java: mCurrentType, arrayCount: 0}; - - var ret_void = (retType.name == "Void" && retType.arrayCount == 0); - - if (is_interface) - { - java_out.writeString(" @Override public " + javaType(retType) + " " + func_name + "("); - - for (i in 0...parsedTypes.length) - { - if (i > 0) java_out.writeString(","); - java_out.writeString(javaType(parsedTypes[i]) + " arg" + i); - } - - java_out.writeString(") {\n"); - - if (parsedTypes.length > 0) java_out.writeString(" Object [] args = new Object[" + parsedTypes.length + "];\n"); - else - java_out.writeString(" Object [] args = null;\n"); - - for (i in 0...parsedTypes.length) - { - if (isJavaObject(parsedTypes[i])) java_out.writeString(" args[" + i + "] = arg" + i + ";\n"); - else - java_out.writeString(" args[" + i + "] = new Value(arg" + i + ");\n"); - } - - if (!ret_void) java_out.writeString(" return (" + javaType(retType) + ")"); - - java_out.writeString(" Lime." + nmeCallType(retType) + "(__haxeHandle,\"" + uniq_name + "\",args)"); - - if (!ret_void) java_out.writeString(")"); - java_out.writeString(";\n }\n"); - - output(" public function " + uniq_name); - outputFunctionArgs(); - output(":"); - - if (ret_full_class) outputType(retType); - else - output("Dynamic"); - output("\n {\n return null;\n }\n \n"); - } - else - { - output(" private static var _" + uniq_name + "_func:Dynamic;\n\n"); - output(" public "); - - if (is_static || constructor) output("static "); - - output(do_override + "function " + uniq_name); - outputFunctionArgs(); - output(":"); - - if (ret_full_class) outputType(retType); - else - output("Dynamic"); - - output("\n"); - output(" {\n"); - func_name = "_" + uniq_name + "_func"; - output(" if (" + func_name + " == null)\n"); - output(" " + func_name + " = openfl.utils.JNI." + (is_static ? "createStaticMethod" : "createMemberMethod")); - output("(\"" + StringTools.replace(mCurrentType, ".", "/") + "\", \"" + mConstants[name_ref] + "\", \"" + mConstants[desc_ref] - + "\", true);\n"); - - output(" var a = new Array();\n"); - - if (!is_static) output(" a.push (__jobject);\n"); - - for (i in 0...parsedTypes.length) - output(" a.push(arg" + i + ");\n"); - - if (ret_void) output(" "); - else if (ret_full_class && !isPOD(retType.name)) output(" return new " + retType.name + "("); - else - output(" return "); - - output(func_name + "(a)"); - - if (ret_full_class && !isPOD(retType.name)) output(");\n"); - else - output(";\n"); - - output(" }\n \n \n"); - } - } - - if (constructor && !constructed) - { - constructed = true; - output(" public function new(handle:Dynamic)\n {\n"); - if (super_ref > 0) output(" super(handle);"); - else - output(" __jobject = handle;"); - output("\n }\n \n \n"); - } - - var att_count = src.readUInt16(); - for (a in 0...att_count) - readAttribute(src, false, false); - } - - if (java_out != null) - { - java_out.writeString("}\n"); - java_out.close(); - - System.mkdir("compiled"); - var nme_path = getHaxelib("openfl") + "/__backends/native/templates/android/template/src"; - System.runCommand("", "javac", [ - "-classpath", - "\"classes/android.jar\";\"" + javaPath.substr(0, javaPath.length - 1) + "\"", - "-sourcepath", - nme_path, - "-d", - "compiled", - "stubs/" + java_name - ], true, true, true); - - // Sys.setCwd("compiled"); - - var class_name = java_name.substr(0, java_name.length - 4) + "class"; - - var dx = Sys.getEnv("ANDROID_SDK") + "/platforms/" + extractedAndroidPaths[0] + "/tools/dx"; - System.runCommand("compiled", dx, ["--dex", "--output=classes.jar", class_name], true, true, true); - - if (FileSystem.exists("classes.jar")) - { - var class_def = File.getBytes("classes.jar"); - class_def = Compress.run(class_def, 9); - var class_str = BaseCode.encode(class_def.toString(), base64); - - output("\n static var classDef = \"" + class_str + "\";\n"); - } - } - - output("}"); - } - - private function parseTypes(type:String, inArrayCount:Int) - { - if (type == "") return; - var is_obj = false; - switch (type.substr(0, 1)) - { - case "[": - parseTypes(type.substr(1), inArrayCount + 1); - case "I": - addType("Int", "int", inArrayCount); - case "C": - addType("Int", "char", inArrayCount); - case "S": - addType("Int", "short", inArrayCount); - case "B": - addType("Int", "byte", inArrayCount); - case "V": - addType("Void", "void", inArrayCount); - case "Z": - addType("Bool", "boolean", inArrayCount); - case "J": - addType("Float", "long", inArrayCount); - case "F": - addType("Float", "float", inArrayCount); - case "D": - addType("Float", "double", inArrayCount); - case "L": - is_obj = true; - var end = type.indexOf(";"); - if (end < 1) throw("Bad object string: " + type); - var name = type.substr(1, end - 1); - addType(processObjectArg(name.split("/").join("."), inArrayCount), name, inArrayCount); - type = type.substr(end); - default: - throw("Unknown java type: " + type); - } - parsedIsObj.push(is_obj); - if (type.length > 1) parseTypes(type.substr(1), 0); - } - - private function processObjectArg(inObj:String, inArrayCount:Int) - { - if (inObj == "java.lang.CharSequence" || inObj == "java.lang.String") return "String"; - if (mExactTypes.exists(inObj) && inArrayCount == 0) return inObj; - return "Dynamic /*" + inObj + "*/"; - } - - private function pushClass(inName:String) - { - if (!mProcessed.get(inName)) - { - mProcessed.set(inName, true); - mStack.push(inName); - } - } - - private function readAttribute(src:Input, inOutputConst:Bool, asString:Bool) - { - var name_ref = src.readUInt16(); - debug(" attr:" + mConstants[name_ref]); - var len = src.readInt32(); - var bytes = Bytes.alloc(len); - src.readBytes(bytes, 0, len); - - if (inOutputConst && mConstants[name_ref] == "ConstantValue") - { - var ref = (bytes.get(0) << 8) + bytes.get(1); - if (asString) output(" = \"" + mConstants[mConstants[ref]] + "\""); - else - output(" = " + mConstants[ref]); - } - } - - private function removeRecursive(file) - { - if (!FileSystem.isDirectory(file)) - { - FileSystem.deleteFile(file); - return; - } - for (f in FileSystem.readDirectory(file)) - removeRecursive(file + "/" + f); - FileSystem.deleteDirectory(file); - } - - private function splitFunctionType(type:String) - { - if (!fmatch.match(type)) throw("Not a function : " + type); - var args = fmatch.matched(1); - retType = toHaxeType(fmatch.matched(2)); - parsedTypes = []; - parsedIsObj = []; - parseTypes(args, 0); - } - - private function toHaxeType(inStr:String) - { - parsedTypes = []; - parsedIsObj = []; - parseTypes(inStr, 0); - return parsedTypes[0]; - } - /*public static function main() - { - var args = Sys.args(); - debug(args.toString()); - - new JavaExternGenerator(args[0], "gen"); - }*/ -} - -typedef JNIType = -{ - name:String, - java:String, - arrayCount:Int -}; diff --git a/tools/utils/PlatformSetup.hx b/tools/utils/PlatformSetup.hx index 9dee297a59..70c4343a3a 100644 --- a/tools/utils/PlatformSetup.hx +++ b/tools/utils/PlatformSetup.hx @@ -365,13 +365,8 @@ class PlatformSetup case "android": setupAndroid(); - case "blackberry": - - // setupBlackBerry (); - case "html5": Log.println("\x1b[0;3mNo additional configuration is required.\x1b[0m"); - // setupHTML5 (); case "ios", "iphoneos", "iphonesim": if (System.hostPlatform == MAC) @@ -391,29 +386,18 @@ class PlatformSetup setupMac(); } - case "tizen": - - // setupTizen (); - case "webassembly", "wasm", "emscripten": setupWebAssembly(); - case "webos": - - // setupWebOS (); - case "electron": setupElectron(); - case "windows", "winrt": + case "windows": if (System.hostPlatform == WINDOWS) { setupWindows(); } - case "neko", "cs", "uwp", "winjs", "nodejs", "java": - Log.println("\x1b[0;3mNo additional configuration is required.\x1b[0m"); - case "hl", "hashlink": setupHL(); @@ -677,122 +661,6 @@ class PlatformSetup } } - public static function setupHTML5():Void - { - // var setApacheCordova = false; - - // var defines = getDefines (); - // var answer = CLIHelper.ask ("Download and install Apache Cordova?"); - - // if (answer == YES || answer == ALWAYS) { - - // var downloadPath = ""; - // var defaultInstallPath = ""; - - // if (System.hostPlatform == WINDOWS) { - - // defaultInstallPath = "C:\\Development\\Apache Cordova"; - - // } else { - - // defaultInstallPath = "/opt/cordova"; - - // } - - // var path = unescapePath (CLIHelper.param ("Output directory [" + defaultInstallPath + "]")); - // path = createPath (path, defaultInstallPath); - - // downloadFile (apacheCordovaPath); - // extractFile (Path.withoutDirectory (apacheCordovaPath), path, "*"); - - // var childArchives = []; - - // for (file in FileSystem.readDirectory (path)) { - - // if (Path.extension (file) == "zip") { - - // childArchives.push (file); - - // } - - // } - - // createPath (path + "/lib"); - // var libs = [ "android", "bada-wac", "bada", "blackberry", "ios", "mac", "qt", "tizen", "tvos", "webos", "wp7" ]; - - // for (archive in childArchives) { - - // var name = Path.withoutExtension (archive); - // name = StringTools.replace (name, "incubator-", ""); - // name = StringTools.replace (name, "cordova-", ""); - - // if (name == "blackberry-webworks") { - - // name = "blackberry"; - - // } - - // var basePath = path + "/"; - - // for (lib in libs) { - - // if (name == lib) { - - // basePath += "lib/"; - - // } - - // } - - // createPath (basePath + name); - // extractFile (path + "/" + archive, basePath + name); - - // } - - // if (System.hostPlatform != WINDOWS) { - - // System.runCommand ("", "chmod", [ "-R", "777", path ], false); - - // } - - // setApacheCordova = true; - // defines.set ("CORDOVA_PATH", path); - // writeConfig (defines.get ("LIME_CONFIG"), defines); - // Log.println (""); - - // } - - // var requiredVariables = []; - // var requiredVariableDescriptions = []; - - // if (!setApacheCordova) { - - // requiredVariables.push ("CORDOVA_PATH"); - // requiredVariableDescriptions.push ("Path to Apache Cordova"); - - // } - - // requiredVariables = requiredVariables.concat ([ "WEBWORKS_SDK", "WEBWORKS_SDK_BBOS", "WEBWORKS_SDK_PLAYBOOK" ]); - // requiredVariableDescriptions = requiredVariableDescriptions.concat ([ "Path to WebWorks SDK for BlackBerry 10", "Path to WebWorks SDK for BBOS", "Path to WebWorks SDK for PlayBook" ]); - - // defines = getDefines (requiredVariables, requiredVariableDescriptions); - - // defines.set ("CORDOVA_PATH", unescapePath (defines.get ("CORDOVA_PATH"))); - // defines.set ("WEBWORKS_SDK_BBOS", unescapePath (defines.get ("WEBWORKS_SDK_BBOS"))); - // defines.set ("WEBWORKS_SDK_PLAYBOOK", unescapePath (defines.get ("WEBWORKS_SDK_PLAYBOOK"))); - - // // temporary hack - - // /*Sys.println (""); - // Sys.println ("Setting Apache Cordova install path..."); - // System.runCommand (defines.get ("CORDOVA_PATH") + "/lib/ios", "make", [ "install" ], true, true); - // Sys.println ("Done.");*/ - - // writeConfig (defines.get ("LIME_CONFIG"), defines); - - // Haxelib.runCommand ("", [ "install", "cordova" ], true, true); - } - public static function setupIOS():Void { Log.println("\x1b[1mIn order to build applications for iOS and tvOS, you must have"); diff --git a/tools/utils/publish/FirefoxMarketplace.hx b/tools/utils/publish/FirefoxMarketplace.hx deleted file mode 100644 index 7c4db193b2..0000000000 --- a/tools/utils/publish/FirefoxMarketplace.hx +++ /dev/null @@ -1,767 +0,0 @@ -package utils.publish; - -import haxe.crypto.Base64; -import hxp.Path; -import haxe.Json; -import lime.tools.helpers.CLIHelper; -import lime.tools.helpers.Log; -import lime.tools.helpers.ZipHelper; -import lime.tools.helpers.ProcessHelper; -import lime.graphics.Image; -import lime.net.oauth.*; -import lime.net.*; -import lime.project.HXProject; -import utils.PlatformSetup; -import sys.FileSystem; -import sys.io.File; - -class FirefoxMarketplace -{ - private static function compress(project:HXProject):String - { - var outputDirectory = project.app.path + "/firefox"; - var source = outputDirectory + "/bin/"; - var packagedFile = project.app.file + ".zip"; - var destination = outputDirectory + "/dist/" + packagedFile; - - System.compress(source, destination); - - return destination; - } - - public static function isValid(project:HXProject):Bool - { - var result = FirefoxHelper.validate(project); - - if (result.errors.length != 0) - { - var errorMsg = "The application cannot be published\n"; - - for (error in result.errors) - { - errorMsg += '\n * ' + error; - } - - if (Log.verbose) Log.println(""); - Log.error(errorMsg); - - return false; - } - - return true; - } - - public static function publish(project:HXProject):Void - { - var devServer = project.targetFlags.exists("dev"); - var forceUpload = project.targetFlags.exists("force"); - var answer:Answer; - - /*if (!devServer) { - - Log.println ("In which server do you want to publish your application?"); - Log.println ("\t1. Production server."); - Log.println ("\t2. Development server."); - Log.println ("\tq. Quit."); - - answer = CLIHelper.ask ("Which server?", ["1", "2", "q"]); - - switch (answer) { - - case CUSTOM (x): - - switch (x) { - - case "2": devServer = true; - case "q": Sys.exit (0); - - } - - default: - - - } - - }*/ - - Log.info("Checking account..."); - - var defines = project.defines; - var existsProd = defines.exists("FIREFOX_MARKETPLACE_KEY") && defines.exists("FIREFOX_MARKETPLACE_SECRET"); - var existsDev = defines.exists("FIREFOX_MARKETPLACE_DEV_KEY") && defines.exists("FIREFOX_MARKETPLACE_DEV_SECRET"); - - if ((!existsProd && !devServer) || (!existsDev && devServer)) - { - setup(false, devServer, cast defines); - - // we need to get all the defines after configuring the account - Log.mute = true; - defines = PlatformSetup.getDefines(); - Log.mute = false; - } - - var baseUrl = devServer ? FirefoxHelper.DEVELOPMENT_SERVER_URL : FirefoxHelper.PRODUCTION_SERVER_URL; - var appID:Int = -1; - var appSlug:String = ""; - var appName = project.meta.title; - - var key = defines.get("FIREFOX_MARKETPLACE" + (devServer ? "_DEV_" : "_") + "KEY"); - var secret = defines.get("FIREFOX_MARKETPLACE" + (devServer ? "_DEV_" : "_") + "SECRET"); - - var marketplace = new MarketplaceAPI(key, secret, devServer); - - var error = function(r:Dynamic) - { - Reflect.deleteField(r, "error"); - // Log.println (""); - Log.error((r.customError != null ? r.customError : 'There was an error:\n\n$r')); - }; - - var response:Dynamic = marketplace.getUserAccount(); - - if (response.error) - { - response.customError = "Could not validate your account, please verify your account information"; - error(response); - } - - // Log.println ("OK"); - - var apps:List = Lambda.filter(marketplace.getUserApps(), function(obj) return appName == Reflect.field(obj.name, "en-US")); - - if (!forceUpload && apps.length > 0) - { - var app = apps.first(); - - Log.println("This application has already been submitted to the Firefox Marketplace."); - answer = CLIHelper.ask("Do you want to open the edit page?", ["y", "n"]); - - if (answer == YES) - { - System.openURL(baseUrl + '/developers/app/${app.slug}/edit'); - } - - Sys.exit(0); - } - - // Log.println ("Submitting \"" + appName + "\" to the Firefox " + (devServer ? "development" : "production") + " server"); - - var packagedFile = compress(project); - - response = marketplace.submitForValidation(packagedFile); - - if (response.error || response.id == null) - { - error(response); - } - - var uploadID = response.id; - - Log.println(""); - // Log.print ('Server validation ($uploadID)'); - Log.print("Waiting for server"); - - do - { - Log.print("."); - response = marketplace.checkValidationStatus(uploadID); - Sys.sleep(1); - } - while (!response.processed); - - Log.println(""); - - if (response.valid) - { - // Log.println (" VALID"); - Log.info("Sending application details..."); - response = marketplace.createApp(uploadID); - - if (response.error || response.id == null) - { - // Log.println ("ERROR"); - error(response); - } - - appID = response.id; - appSlug = response.slug; - - // Log.println ("OK"); - // Log.print ("Updating application information... "); - response = marketplace.updateAppInformation(appID, project); - - if (response.error) - { - // Log.println ("ERROR"); - error(response); - } - - // Log.println ("OK"); - // Log.println ("Updating screenshots:"); - - var screenshots:Array = project.config.getArrayString("firefox-marketplace.screenshots.screenshot", "path"); - - for (i in 0...screenshots.length) - { - response = marketplace.uploadScreenshot(appID, i, screenshots[i]); - Log.println(""); - - if (response.error) - { - error(response); - } - } - - var urlApp = baseUrl + '/app/$appSlug/'; - var devUrlApp = baseUrl + '/developers/app/$appSlug/'; - var urlContentRatings = devUrlApp + "content_ratings/edit"; - - var havePayments = project.config.getString("firefox-marketplace.premium-type", "free") != cast PremiumType.FREE; - - Log.println(""); - Log.info("Application submitted!"); - Sys.sleep(1); - Log.println(""); - Log.info("Before the application is fully published, you will need to fill out a content"); - Log.info("rating questionnaire, and send the application for review"); - Log.println(""); - var answer = CLIHelper.ask("Would you like to complete your submission now?"); - - if (answer == YES || answer == ALWAYS) - { - if (Log.verbose) Log.println(""); - System.openURL(urlContentRatings); - } - else - { - Log.println(""); - Log.info("You can complete your submission later by going to " + devUrlApp); - } - - /* - Log.println (""); - Log.warn ("Before this application can be reviewed & published:"); - Log.warn ("* You will need to fill the contents rating questionnaire *"); - - if (havePayments) Log.warn ("* You will need to add or link a payment account *"); - - Log.println (""); - Log.println ("1. Open the contents rating questionnaire page."); - Log.println ("2. Open the application edit page."); - Log.println ("3. Open the application listing page."); - Log.println ("q. I'm fine, thanks."); - - answer = CLIHelper.ask ("Open the questionnaire now?", ["1", "2", "3", "q"]); - - switch (answer) { - - case CUSTOM (x): - - switch (x) { - - case "1": System.openURL (urlContentRatings); - case "2": System.openURL (devUrlApp); - case "3": System.openURL (urlApp); - case _: - - } - - default: - - - } - - Log.println (""); - Log.println ("Your application listing page is:"); - Log.println ('$urlApp'); - Log.println (""); - Log.println ("Goodbye!"); */ - } - else - { - // Log.println (" FAILED"); - Log.println(""); - - var errorMsg = "Application failed server validation"; - - var errors:List = Lambda.filter(response.validation.messages, function(m) return m.type == "error"); - var n = 1; - - for (error in errors) - { - errorMsg += ('\n * ${error.description.join(" ")}'); - } - - // errorMsg += "\nPlease refer to the documentation to fix the issues."; - marketplace.close(); - Log.error(errorMsg); - } - - marketplace.close(); - } - - public static function setup(askServer:Bool = true, devServer:Bool = false, defines:Map = null):Void - { - if (defines == null) - { - defines = PlatformSetup.getDefines(); - } - - var existsProd = defines.exists("FIREFOX_MARKETPLACE_KEY") && defines.exists("FIREFOX_MARKETPLACE_SECRET"); - var existsDev = defines.exists("FIREFOX_MARKETPLACE_DEV_KEY") && defines.exists("FIREFOX_MARKETPLACE_DEV_SECRET"); - - // TODO warning about the override of the account - - Log.println("You need to link your developer account to publish to the Firefox Marketplace"); - var answer = CLIHelper.ask("Would you like to open the developer site now?"); - - if (answer == YES || answer == ALWAYS) - { - var server = ""; - - /*if (askServer) { - - Log.println (""); - Log.println ("First of all you need to select the server you want to setup your account."); - Log.println ("Each server has its own configuration and can't be shared."); - Log.println ("\t1. Production server (" + FirefoxHelper.PRODUCTION_SERVER_URL + ")"); - Log.println ("\t2. Development server (" + FirefoxHelper.DEVELOPMENT_SERVER_URL + ")"); - Log.println("\tq. Cancel"); - answer = CLIHelper.ask ("Choose the server to setup your Firefox Marketplace account.", ["1", "2", "q"]); - - } else {*/ - - answer = devServer ? CUSTOM("2") : CUSTOM("1"); - - // } - - switch (answer) - { - case CUSTOM("1"): - server = FirefoxHelper.PRODUCTION_SERVER_URL; - devServer = false; - - case CUSTOM("2"): - server = FirefoxHelper.DEVELOPMENT_SERVER_URL; - devServer = true; - - default: - Sys.exit(0); - } - - /*if ((existsProd && !devServer) || (existsDev && devServer)) { - - Log.info (""); - Log.warn ("You will override your account settings!"); - answer = CLIHelper.ask ("Are you sure?", ["y", "n"]); - - if (answer == NO) { - - Sys.exit (0); - - } - - }*/ - - Log.println(""); - Log.info("Opening \"" + server + "/developers/api\"..."); - Log.println(""); - Log.info(" * Create a new account or login"); - Log.info(" * Choose \"Command line\" as the client type then press \"Create\""); - - Sys.sleep(3); - if (Log.verbose) Log.println(""); - System.openURL(server + "/developers/api"); - Sys.sleep(2); - - Log.println(""); - Log.info("\x1b[1mPress any key to continue\x1b[0m"); - - try - { - Sys.stdin().readLine(); - } - catch (e:Dynamic) - { - Sys.exit(0); - } - } - - var key = StringTools.trim(CLIHelper.param("OAuth Key")); - var secret = StringTools.trim(CLIHelper.param("OAuth Secret")); - - Log.println(""); - - var marketplace = new MarketplaceAPI(key, secret, devServer); - var name:String = ""; - var account:Dynamic; - var valid = false; - - do - { - Log.println("Checking account..."); - account = marketplace.getUserAccount(); - - if (account != null && account.display_name != null) - { - name = account.display_name; - valid = true; - } - - if (!valid) - { - Log.println("There was a problem connecting to your developer account"); - answer = CLIHelper.ask("Would you like to try again?"); - - if (answer == YES) - { - Log.println(""); - key = StringTools.trim(CLIHelper.param("OAuth Key")); - secret = StringTools.trim(CLIHelper.param("OAuth Secret")); - Log.println(""); - - marketplace.client.consumer.key = key; - marketplace.client.consumer.secret = secret; - } - else - { - marketplace.close(); - Sys.exit(0); - } - } - } - while (!valid); - - Log.println("Hello " + name + "!"); - - Log.mute = true; - defines = PlatformSetup.getDefines(); - Log.mute = false; - - defines.set("FIREFOX_MARKETPLACE" + (devServer ? "_DEV_" : "_") + "KEY", key); - defines.set("FIREFOX_MARKETPLACE" + (devServer ? "_DEV_" : "_") + "SECRET", secret); - - PlatformSetup.writeConfig(defines.get("LIME_CONFIG"), defines); - Log.println(""); - } -} - -class FirefoxHelper -{ - public static inline var PRODUCTION_SERVER_URL = "https://marketplace.firefox.com"; - public static inline var DEVELOPMENT_SERVER_URL = "https://marketplace-dev.allizom.org"; - private static inline var TITLE_MAX_CHARS = 127; - private static inline var MAX_CATEGORIES = 2; - private static var MIN_WH_SCREENSHOT = {width: 320, height: 480}; - - private static function isScreenshotValid(path:String):Bool - { - if (FileSystem.exists(path)) - { - var img = Image.fromFile(path); - var portrait = img.width >= MIN_WH_SCREENSHOT.width && img.height >= MIN_WH_SCREENSHOT.height; - var landscape = img.width >= MIN_WH_SCREENSHOT.height && img.height >= MIN_WH_SCREENSHOT.width; - return portrait || landscape; - } - - return false; - } - - public static function validate(project:HXProject):{errors:Array, warnings:Array} - { - var errors:Array = []; - var warnings:Array = []; - - // We will check if the project has the minimal required fields for publishing to the Firefox Marketplace - - if (project.meta.title == "") - { - errors.push("You need to have a title\n\n\t\n"); - } - - if (project.meta.title.length > TITLE_MAX_CHARS) - { - errors.push("Your title is too long (max " + TITLE_MAX_CHARS + " characters)\n"); - } - - if (project.config.getString("firefox-marketplace.description", project.meta.description) == "") - { - errors.push("You need to have a description\n\n\t\n"); - } - - if (project.meta.company == "") - { - errors.push("You need to have a company name\n\n\t\n"); - } - - if (project.meta.companyUrl == "") - { - errors.push("You need to have a company URL\n\n\t\n"); - } - - var categories = project.config.getArrayString("firefox-marketplace.categories.category", "name"); - - if (categories.length == 0) - { - errors.push("You need to have at least one category\n\n\t\n\t \n\t \n\t \n\t\n"); - } - else if (categories.length > MAX_CATEGORIES) - { - errors.push("You cannot have more than two categories"); - } - - if (project.config.getString("firefox-marketplace.privacyPolicy") == "") - { - errors.push("You need to have a privacy policy\n\n\t\n\t Policy detail\n\t\n"); - } - - if (project.config.getString("firefox-marketplace.support.email") == "") - { - errors.push("You need to have a support email address\n\n\t\n\t \n\t\n"); - } - - var screenshots = project.config.getArrayString("firefox-marketplace.screenshots.screenshot", "path"); - - if (screenshots.length == 0) - { - errors.push("You need to have at least one screenshot\n\n\t\n\t \n\t \n\t \n\t\n"); - } - else - { - for (path in screenshots) - { - if (!isScreenshotValid(path)) - { - if (!FileSystem.exists(path)) - { - errors.push("Screenshot \"" + Path.withoutDirectory(path) + "\" does not exist\n"); - } - else - { - errors.push("Screenshot \"" + Path.withoutDirectory(path) + "\" must be at least 320 x 480 in size\n"); - } - } - } - } - - return {errors: errors, warnings: warnings}; - } -} - -class MarketplaceAPI -{ - private static inline var API_PATH = "/api/v1/"; - - public var client:OAuthClient; - - private var loader:URLLoader; - private var entryPoint:String; - - public function new(key:String = null, secret:String = null, devServer:Bool = false) - { - loader = new URLLoader(); - - if (key != null && secret != null) - { - client = new OAuthClient(OAuthVersion.V1, new OAuthConsumer(key, secret)); - } - - entryPoint = (devServer ? FirefoxHelper.DEVELOPMENT_SERVER_URL : FirefoxHelper.PRODUCTION_SERVER_URL) + API_PATH; - } - - public function checkValidationStatus(uploadID:String):Dynamic - { - var response = load(GET, 'apps/validation/$uploadID/', null); - return response; - } - - public function close():Void - { - loader.close(); - } - - public function createApp(uploadID:String):Dynamic - { - var response = load(POST, 'apps/app/', Json.stringify({upload: uploadID})); - return response; - } - - public function customRequest(method:URLRequestMethod, path:String, ?data:Dynamic):URLRequest - { - var request:URLRequest; - - if (client == null) - { - request = new URLRequest(entryPoint + path); - } - else - { - request = client.createRequest(method, entryPoint + path); - } - - request.method = method; - request.data = data; - request.contentType = "application/json"; - - return request; - } - - public function getUserAccount():Dynamic - { - var response = load(GET, "account/settings/mine/", null); - return response; - } - - public function getUserApps():Array - { - var result:Array = []; - var response = load(GET, 'apps/app/', null); - - if (!response.error && response.objects != null) - { - for (obj in cast(response.objects, Array)) - { - result.push(obj); - } - } - - return result; - } - - private function load(method:URLRequestMethod, path:String, data:String = null, progressMsg:String = null):Dynamic - { - var response:Dynamic = {}; - var status = 0; - var request = customRequest(method, path, data); - var withProgress = progressMsg != null && progressMsg.length > 0 && data != null; - - var uploadingFunc:URLLoader->Int->Int->Void = null; - - if (withProgress) - { - uploadingFunc = function(l, up, dl) CLIHelper.progress('$progressMsg', up, data.length); - loader.onProgress.add(uploadingFunc); - } - - loader.onHTTPStatus.add(function(_, s) status = s, true); - - loader.onComplete.add(function(l) - { - response = Json.parse(l.data); - - if (withProgress) l.onProgress.remove(uploadingFunc); - }, true); - - loader.load(request); - - response.error = false; - - if (status >= 400) - { - response.error = true; - } - - return response; - } - - public function submitForValidation(path:String, type:String = "application/zip"):Dynamic - { - var p = new Path(path); - var response:Dynamic = {}; - - if (FileSystem.exists(path) && p.ext == "zip") - { - var base = Base64.encode(File.getBytes(path)); - var filename = p.file + "." + p.ext; - - var upload = - { - upload: - { - type: type, - name: filename, - data: base - } - }; - - response = load(POST, "apps/validation/", Json.stringify(upload), "Uploading:"); - } - else - { - response.error = true; - response.customError = 'File $path doesn\'t exist'; - } - - return response; - } - - public function updateAppInformation(appID:Int, project:HXProject):Dynamic - { - var object = - { - name: project.meta.title, - categories: project.config.getArrayString("firefox-marketplace.categories.category", "name"), - description: project.config.getString("firefox-marketplace.description", project.meta.description), - privacy_policy: project.config.getString("firefox-marketplace.privacyPolicy"), - homepage: project.config.getString("firefox-marketplace.homepage"), - support_url: project.config.getString("firefox-marketplace.support.url"), - support_email: project.config.getString("firefox-marketplace.support.email"), - device_types: project.config.getArrayString("firefox-marketplace.devices.device", "type", ["firefoxos", "desktop"]), - premium_type: project.config.getString("firefox-marketplace.premium-type", "free"), - price: project.config.getString("firefox-marketplace.config.price", "0.99"), - }; - - var response = load(PUT, 'apps/app/$appID/', Json.stringify(object)); - return response; - } - - public function uploadScreenshot(appID:Int, position:Int, path:String):Dynamic - { - var response:Dynamic = {}; - - if (FileSystem.exists(path)) - { - var p = new Path(path); - var type = p.ext == "png" ? "image/png" : "image/jpeg"; - var base = Base64.encode(File.getBytes(path)); - var filename = p.file + "." + p.ext; - - var screenshot = - { - position: position, - file: - { - type: type, - name: filename, - data: base, - } - }; - - response = load(POST, 'apps/app/$appID/preview/', Json.stringify(screenshot), 'Uploading screenshot:'); - } - else - { - response.error = true; - response.customError = 'File "$path" does not exist'; - } - - return response; - } -} - -@:enum abstract DeviceType(String) -{ - var FIREFOXOS = "firefoxos"; - var DESKTOP = "desktop"; - var MOBILE = "mobile"; - var TABLET = "tablet"; -} - -@:enum abstract PremiumType(String) -{ - var FREE = "free"; - var FREE_INAPP = "free-inapp"; - var PREMIUM = "premium"; - var PREMIUM_INAPP = "premium-inapp"; - var OTHER = "other"; -}