5 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
6 ActiveX, OleCtrls, HTMLDocumentEvent,
16 TPreviewBrowser = class(TWebBrowser)
18 FEvent: THTMLDocumentEventSink;//
\83u
\83\89\83E
\83U
\83h
\83L
\83\85\83\81\83\93\83g
\83C
\83x
\83\93\83g
19 function makeHTML(const URL, Host, Document : String): String;
20 procedure BrowserDocumentComplete(Sender: TObject;
21 const pDisp: IDispatch; var URL: OleVariant);
22 function PreviewDbClick(Sender: TObject): WordBool;
24 procedure CreateParams(var Params: TCreateParams); override;
26 constructor Create(AOwner: TComponent); override;
27 destructor Destroy; override;
28 procedure PreviewImage(URL : String);
29 function GetWindowRect(Point: TPoint) : TRect;
33 uses MojuUtils, GikoSystem, Setting, Giko;
36 //
\83v
\83\8c\83r
\83\85\81[
\83t
\83@
\83C
\83\8b\96¼
37 HTML_FILE_NAME = 'temp_preview.html';
38 //
\83}
\83E
\83X
\83J
\81[
\83\
\83\8b\82©
\82ç
\82Ì
\82¸
\82ç
\82µ
\88Ê
\92u
41 NICO = 'www.nicovideo.jp';
43 constructor TPreviewBrowser.Create(AOwner: TComponent);
45 inherited Create(AOwner);
47 OnDocumentComplete := BrowserDocumentComplete;
50 destructor TPreviewBrowser.Destroy;
52 if (FEvent <> nil) then begin
58 procedure TPreviewBrowser.CreateParams(var Params: TCreateParams);
63 \brief
\8ew
\92è
\82³
\82ê
\82½URL
\82Ì
\83v
\83\8c\83r
\83\85\81[
64 \param URL
\83v
\83\8c\83r
\83\85\81[
\82·
\82é
\83C
\83\81\81[
\83W
\82ÌURL
66 procedure TPreviewBrowser.PreviewImage(URL : String);
68 HtmlFileName : string;
70 Protocol, Host, Path, Document, Port, Bookmark : string;
73 TargetFrameName: OleVariant;
77 GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
78 Referer := Protocol + '://' + Host;
80 Referer := Referer + ':' + Port;
81 Referer := Referer + Path;
82 Headers := 'Referer: ' + Referer;
84 TargetFrameName := '';
87 HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME;
88 sl := TStringList.Create;
91 sl.Text := makeHTML(URL, Host, Document);
92 sl.SaveToFile(HtmlFileName);
100 Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
104 \breif
\95\
\8e¦
\82·
\82é
\83E
\83B
\83\93\83h
\83E
\83T
\83C
\83Y
\82ð
\8eæ
\93¾
\82·
\82é
105 \param Point
\83}
\83E
\83X
\83J
\81[
\83\
\83\8b\82Ì
\8dÀ
\95W
107 function TPreviewBrowser.GetWindowRect(Point: TPoint) : TRect;
109 WindowWidth, WindowHeight : Integer;
111 //
\90Ý
\92è
\82É
\82æ
\82é
\8fê
\8d\87\82í
\82¯
112 case GikoSys.Setting.PreviewSize of
129 else begin //gpsMedium
135 Result := Rect(0, 0, WindowWidth, WindowHeight);
136 // bata55
\88È
\91O
\82Í
\8d¶
\89E
\82ª
\8aÔ
\88á
\82Á
\82Ä
\82½
137 //
\8fo
\82µ
\88Ê
\92u
\82É
\82æ
\82é
\95â
\90³
138 case GikoSys.Setting.PopupPosition of
139 gppLeftTop: OffsetRect(Result,
140 Point.x - WindowWidth - DIV_X, Point.y - WindowHeight - DIV_Y);
141 gppLeft: OffsetRect(Result,
142 Point.x - WindowWidth - DIV_X, Point.y - (WindowHeight div 2));
143 gppLeftBottom: OffsetRect(Result,
144 Point.x - WindowWidth - DIV_X, Point.y + DIV_Y);
145 gppTop: OffsetRect(Result,
146 Point.x - (WindowWidth div 2), Point.y - WindowHeight - DIV_Y);
147 gppCenter: OffsetRect(Result,
148 Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2));
149 gppBottom: OffsetRect(Result,
150 Point.x - (WindowWidth div 2), Point.y + DIV_Y);
151 gppRightTop: OffsetRect(Result,
152 Point.x + DIV_X, Point.y - WindowHeight - DIV_Y);
153 gppRight: OffsetRect(Result,
154 Point.x + DIV_X, Point.y - (WindowHeight div 2));
155 gppRightBottom: OffsetRect(Result, Point.x + DIV_X, Point.y + DIV_Y); //
\83M
\83R
\83i
\83r
\83X
\83\8c \83p
\81[
\83g
\82P
\82Ì453
\8e\81\82É
\8a´
\8eÓ
161 \breif
\83v
\83\8c\83r
\83\85\81[
\97p
\82ÌHTML
\82ð
\8dì
\90¬
\82·
\82é
162 \param URL
\83v
\83\8c\83r
\83\85\81[
\82·
\82é
\83C
\83\81\81[
\83W
\83t
\83@
\83C
\83\8b
164 function TPreviewBrowser.makeHTML(const URL, Host, Document : String): String;
169 if (Pos('http://www.nicovideo.jp/watch/', URL) <> 1) then begin
170 Result := '<html><head>'#13#10
172 + 'function init() {'#13#10
173 + ' if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
175 + ' var dh, ih;'#13#10
176 + ' dh = document.body.clientWidth / document.body.clientHeight;'#13#10
177 + ' ih = Image1.width / Image1.height;'#13#10
178 + ' if (document.body.clientWidth < document.body.clientHeight) {'#13#10
179 + ' if (ih > dh)'#13#10
180 + ' Image1.width = document.body.clientWidth;'#13#10
182 + ' Image1.height = document.body.clientHeight;'#13#10
184 + ' if (ih < dh)'#13#10
185 + ' Image1.height = document.body.clientHeight;'#13#10
187 + ' Image1.width = document.body.clientWidth;'#13#10
190 + ' Message.style.display = "none";'#13#10
194 + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
195 + '<div align="center" id="Message">
\83v
\83\8c\83r
\83\85\81[
\8dì
\90¬
\92\86</div>'#13#10
196 + '<div align="center"><img name="Image1" border="0" src="' + URL + '"></div>'#13#10
199 // <div><iframe width="340" height="185" src="http://www.nicovideo.jp/thumb/sm2494604" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div><div class=link_nicovideo_title><a href="" title="" target="_blank"></a></div>
200 rect := GetWindowRect(point);
202 Result := '<html><head>'#13#10
204 + 'function init() {'#13#10
205 + ' Message.style.display = "none";'#13#10
209 + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
210 + '<div align="center" id="Message">
\83v
\83\8c\83r
\83\85\81[
\8dì
\90¬
\92\86</div>'#13#10
211 + '<div><iframe width="' + IntToStr(rect.Right - rect.Left) +'" height="' + IntToStr(rect.Bottom - rect.Top) + '" src="http://' + Host + '/thumb/' + Document + '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div>'
215 //!
\83h
\83L
\83\85\83\81\83\93\83g
\8a®
\97¹
\83C
\83x
\83\93\83g
216 procedure TPreviewBrowser.BrowserDocumentComplete(Sender: TObject;
217 const pDisp: IDispatch; var URL: OleVariant);
219 if (URL <> 'about:blank') then begin
220 FEvent := THTMLDocumentEventSink.Create(Self, Self.OleObject.Document,
221 HTMLDocumentEvents2);
222 FEvent.OnDoubleClick := PreviewDbClick;
224 if (FEvent <> nil) then begin
229 function TPreviewBrowser.PreviewDbClick(Sender: TObject): WordBool;
231 //
\8e©
\95ª
\82Å
\8e©
\95ª
\82Í
\8fÁ
\82¹
\82È
\82¢
\82Ì
\82Å
\81A
\83\81\83b
\83Z
\81[
\83W
\8co
\97R
\82Å
\8fÁ
\82µ
\82Ä
\82à
\82ç
\82¤
232 PostMessage( GikoForm.Handle , USER_POPUPCLEAR, Integer( Self ), 0 );