@@ -87,13 +87,16 @@ class CWebWindow
87
87
88
88
wil::com_ptr_t <ICoreWebView2Settings> settings;
89
89
m_webview->get_Settings (&settings);
90
- settings->put_IsScriptEnabled (TRUE );
91
- settings->put_AreDefaultScriptDialogsEnabled (TRUE );
92
- settings->put_IsWebMessageEnabled (TRUE );
93
- settings->put_AreDevToolsEnabled (TRUE );
94
- auto settings2 = settings.try_query <ICoreWebView2Settings2>();
95
- if (settings2)
96
- settings2->put_UserAgent (userAgent.c_str ());
90
+ if (settings)
91
+ {
92
+ settings->put_IsScriptEnabled (TRUE );
93
+ settings->put_AreDefaultScriptDialogsEnabled (TRUE );
94
+ settings->put_IsWebMessageEnabled (TRUE );
95
+ settings->put_AreDevToolsEnabled (TRUE );
96
+ auto settings2 = settings.try_query <ICoreWebView2Settings2>();
97
+ if (settings2)
98
+ settings2->put_UserAgent (userAgent.c_str ());
99
+ }
97
100
98
101
m_webview->add_NewWindowRequested (
99
102
Callback<ICoreWebView2NewWindowRequestedEventHandler>(
@@ -140,6 +143,7 @@ class CWebWindow
140
143
}).Get (), nullptr );
141
144
142
145
m_webview->CallDevToolsProtocolMethod (L" Page.enable" , L" {}" , nullptr );
146
+ /*
143
147
m_webview->CallDevToolsProtocolMethod(L"Network.enable", L"{}", nullptr);
144
148
m_webview->CallDevToolsProtocolMethod(L"Log.enable", L"{}", nullptr);
145
149
@@ -154,6 +158,7 @@ class CWebWindow
154
158
return m_parent->OnDevToolsProtocolEventReceived(sender, args, event2);
155
159
}).Get(), nullptr);
156
160
}
161
+ */
157
162
158
163
if (args && deferral)
159
164
{
@@ -533,30 +538,40 @@ class CWebWindow
533
538
534
539
HRESULT SaveText (FILE *fp, const WValue& value)
535
540
{
536
- HRESULT hr = S_OK;
541
+ const int nodeType = value[L" nodeType" ].GetInt ();
542
+ const auto * nodeName = value[L" nodeName" ].GetString ();
543
+ const bool fInline = IsInlineElement (nodeName);
544
+
537
545
if (value[L" nodeType" ].GetInt () == 3 /* #text */ )
538
546
{
539
547
if (fwprintf (fp, L" %s" , value[L" nodeValue" ].GetString ()) < 0 )
540
- hr = HRESULT_FROM_WIN32 (GetLastError ());
541
- if (!IsInlineElement (value[L" nodeName" ].GetString ()))
542
- fwprintf (fp, L" \n " );
548
+ return HRESULT_FROM_WIN32 (GetLastError ());
543
549
}
544
- const auto & nodeName = value[L" nodeName" ].GetString ();
545
- if (wcscmp (nodeName, L" SCRIPT" ) != 0 && wcscmp (nodeName, L" STYLE" ) != 0 )
550
+ if (value.HasMember (L" children" ) && value[L" children" ].IsArray ())
546
551
{
547
- if (value. HasMember ( L" children " ) && value[ L" children " ]. IsArray () )
552
+ if (wcscmp (nodeName, L" SCRIPT " ) != 0 && wcscmp (nodeName, L" STYLE " ) != 0 )
548
553
{
554
+ int textCount = 0 ;
549
555
for (const auto & child : value[L" children" ].GetArray ())
550
556
{
551
- HRESULT hr2 = SaveText (fp, child);
552
- if (FAILED (hr2))
553
- hr = hr2;
557
+ int childNodeType = child[L" nodeType" ].GetInt ();
558
+ if (childNodeType == 3 )
559
+ textCount++;
560
+ HRESULT hr = SaveText (fp, child);
561
+ if (FAILED (hr))
562
+ return hr;
554
563
}
564
+ if ((!fInline && textCount > 0 ) || wcscmp (nodeName, L" BR" ) == 0 || wcscmp (nodeName, L" HR" ) == 0 )
565
+ fwprintf (fp, L" \n " );
555
566
}
556
- if (value.HasMember (L" contentDocument" ))
557
- hr = SaveText (fp, value[L" contentDocument" ]);
558
567
}
559
- return hr;
568
+ if (value.HasMember (L" contentDocument" ))
569
+ {
570
+ HRESULT hr = SaveText (fp, value[L" contentDocument" ]);
571
+ if (FAILED (hr))
572
+ return hr;
573
+ }
574
+ return S_OK;
560
575
}
561
576
562
577
HRESULT SaveText (const std::wstring& filename, IWebDiffCallback* callback)
@@ -1079,48 +1094,52 @@ class CWebWindow
1079
1094
}
1080
1095
}
1081
1096
1097
+ static int cmp (const void * a, const void * b)
1098
+ {
1099
+ const wchar_t * const * pa = reinterpret_cast <const wchar_t * const *>(a);
1100
+ const wchar_t * const * pb = reinterpret_cast <const wchar_t * const *>(b);
1101
+ return wcscmp (*pa, *pb);
1102
+ }
1103
+
1082
1104
static bool IsInlineElement (const wchar_t * name)
1083
1105
{
1084
1106
static const wchar_t * inlineElements[] =
1085
1107
{
1086
- L" B" ,
1087
- L" BIG" ,
1088
- L" I" ,
1089
- L" SMALL" ,
1090
- L" TT" ,
1108
+ L" A" ,
1091
1109
L" ABBR" ,
1092
1110
L" ACRONYM" ,
1111
+ L" B" ,
1112
+ L" BDO" ,
1113
+ L" BIG" ,
1114
+ L" BR" ,
1115
+ L" BUTTON" ,
1093
1116
L" CITE" ,
1094
1117
L" CODE" ,
1095
1118
L" DFN" ,
1096
1119
L" EM" ,
1097
- L" KBD" ,
1098
- L" STRONG" ,
1099
- L" SAMP" ,
1100
- L" VAR" ,
1101
- L" A" ,
1102
- L" BDO" ,
1103
- L" BR" ,
1120
+ L" I" ,
1104
1121
L" IMG" ,
1122
+ L" INPUT" ,
1123
+ L" KBD" ,
1124
+ L" LABEL" ,
1105
1125
L" MAP" ,
1106
1126
L" OBJECT" ,
1107
1127
L" Q" ,
1128
+ L" SAMP" ,
1108
1129
L" SCRIPT" ,
1130
+ L" SELECT" ,
1131
+ L" SMALL" ,
1109
1132
L" SPAN" ,
1133
+ L" STRONG" ,
1110
1134
L" SUB" ,
1111
1135
L" SUP" ,
1112
- L" BUTTON" ,
1113
- L" INPUT" ,
1114
- L" LABEL" ,
1115
- L" SELECT" ,
1116
1136
L" TEXTAREA" ,
1137
+ L" TT" ,
1138
+ L" VAR" ,
1117
1139
};
1118
- for (const auto * inlineName: inlineElements)
1119
- {
1120
- if (wcscmp (name, inlineName) == 0 )
1121
- return true ;
1122
- }
1123
- return false ;
1140
+ return bsearch (&name, inlineElements,
1141
+ sizeof (inlineElements) / sizeof (inlineElements[0 ]),
1142
+ sizeof (inlineElements[0 ]), cmp);
1124
1143
}
1125
1144
1126
1145
static std::wstring Escape (const std::wstring& text)
0 commit comments