interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- ActiveX, ShDocVw;
-
+ ActiveX, OleCtrls, HTMLDocumentEvent,
+{$IF Defined(DELPRO) }
+ SHDocVw,
+ MSHTML
+{$ELSE}
+ SHDocVw_TLB,
+ MSHTML_TLB
+{$IFEND}
+;
type
TPreviewBrowser = class(TWebBrowser)
private
+ FEvent: THTMLDocumentEventSink;//\83u\83\89\83E\83U\83h\83L\83\85\83\81\83\93\83g\83C\83x\83\93\83g
+ function makeHTML(const URL, Host, Document : String): String;
+ procedure BrowserDocumentComplete(Sender: TObject;
+ const pDisp: IDispatch; var URL: OleVariant);
+ function PreviewDbClick(Sender: TObject): WordBool;
protected
procedure CreateParams(var Params: TCreateParams); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
+ procedure PreviewImage(URL : String);
+ function GetWindowRect(Point: TPoint) : TRect;
end;
implementation
+uses MojuUtils, GikoSystem, Setting, Giko;
+
+const
+ //\83v\83\8c\83r\83\85\81[\83t\83@\83C\83\8b\96¼
+ HTML_FILE_NAME = 'temp_preview.html';
+ // \83}\83E\83X\83J\81[\83\\83\8b\82©\82ç\82Ì\82¸\82ç\82µ\88Ê\92u
+ DIV_X = 15;
+ DIV_Y = 15;
+ NICO = 'www.nicovideo.jp';
constructor TPreviewBrowser.Create(AOwner: TComponent);
-var
- Style: Longint;
begin
inherited Create(AOwner);
-// Style := GetWindowLong(Self.Handle, GWL_EXSTYLE);
-// SetWindowLong(Self.Handle, GWL_EXSTYLE, Style or WS_EX_APPWINDOW);
+ FEvent := nil;
+ OnDocumentComplete := BrowserDocumentComplete;
end;
destructor TPreviewBrowser.Destroy;
begin
+ if (FEvent <> nil) then begin
+ FreeAndNil(FEvent);
+ end;
inherited Destroy;
end;
procedure TPreviewBrowser.CreateParams(var Params: TCreateParams);
begin
inherited;
-// Params.Style := WS_POPUP or {or WS_BORDER};
-// Params.WindowClass.Style := Params.WindowClass.Style or CS_SAVEBITS;
-// Params.ExStyle := WS_EX_TOOLWINDOW;
-// AddBiDiModeExStyle(Params.ExStyle);
+end;
+{
+\brief \8ew\92è\82³\82ê\82½URL\82Ì\83v\83\8c\83r\83\85\81[
+\param URL \83v\83\8c\83r\83\85\81[\82·\82é\83C\83\81\81[\83W\82ÌURL
+}
+procedure TPreviewBrowser.PreviewImage(URL : String);
+var
+ HtmlFileName : string;
+ sl : TStringList;
+ Protocol, Host, Path, Document, Port, Bookmark : string;
+ Referer : string;
+ Flags: OleVariant;
+ TargetFrameName: OleVariant;
+ PostData: OleVariant;
+ Headers: OleVariant;
+begin
+ GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
+ Referer := Protocol + '://' + Host;
+ if Port <> '' then
+ Referer := Referer + ':' + Port;
+ Referer := Referer + Path;
+ Headers := 'Referer: ' + Referer;
+ Flags := 0;
+ TargetFrameName := '';
+ PostData := '';
+
+ HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME;
+ sl := TStringList.Create;
+ try
+ try
+ sl.Text := makeHTML(URL, Host, Document);
+ sl.SaveToFile(HtmlFileName);
+ finally
+ sl.Free;
+ end;
+ except
+ end;
+
+
+ Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
+
+end;
+{
+\breif \95\\8e¦\82·\82é\83E\83B\83\93\83h\83E\83T\83C\83Y\82ð\8eæ\93¾\82·\82é
+\param Point \83}\83E\83X\83J\81[\83\\83\8b\82Ì\8dÀ\95W
+}
+function TPreviewBrowser.GetWindowRect(Point: TPoint) : TRect;
+var
+ WindowWidth, WindowHeight : Integer;
+begin
+ // \90Ý\92è\82É\82æ\82é\8fê\8d\87\82í\82¯
+ case GikoSys.Setting.PreviewSize of
+ gpsXSmall: begin
+ WindowWidth := 128;
+ WindowHeight := 96;
+ end;
+ gpsSmall: begin
+ WindowWidth := 256;
+ WindowHeight := 192;
+ end;
+ gpsLarge: begin
+ WindowWidth := 512;
+ WindowHeight := 384;
+ end;
+ gpsXLarge: begin
+ WindowWidth := 640;
+ WindowHeight := 480;
+ end;
+ else begin //gpsMedium
+ WindowWidth := 384;
+ WindowHeight := 288;
+ end;
+ end;
+
+ Result := Rect(0, 0, WindowWidth, WindowHeight);
+ // bata55\88È\91O\82Í\8d¶\89E\82ª\8aÔ\88á\82Á\82Ä\82½
+ // \8fo\82µ\88Ê\92u\82É\82æ\82é\95â\90³
+ case GikoSys.Setting.PopupPosition of
+ gppLeftTop: OffsetRect(Result,
+ Point.x - WindowWidth - DIV_X, Point.y - WindowHeight - DIV_Y);
+ gppLeft: OffsetRect(Result,
+ Point.x - WindowWidth - DIV_X, Point.y - (WindowHeight div 2));
+ gppLeftBottom: OffsetRect(Result,
+ Point.x - WindowWidth - DIV_X, Point.y + DIV_Y);
+ gppTop: OffsetRect(Result,
+ Point.x - (WindowWidth div 2), Point.y - WindowHeight - DIV_Y);
+ gppCenter: OffsetRect(Result,
+ Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2));
+ gppBottom: OffsetRect(Result,
+ Point.x - (WindowWidth div 2), Point.y + DIV_Y);
+ gppRightTop: OffsetRect(Result,
+ Point.x + DIV_X, Point.y - WindowHeight - DIV_Y);
+ gppRight: OffsetRect(Result,
+ Point.x + DIV_X, Point.y - (WindowHeight div 2));
+ 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Ó
+ end;
+
+end;
+
+{
+\breif \83v\83\8c\83r\83\85\81[\97p\82ÌHTML\82ð\8dì\90¬\82·\82é
+\param URL \83v\83\8c\83r\83\85\81[\82·\82é\83C\83\81\81[\83W\83t\83@\83C\83\8b
+}
+function TPreviewBrowser.makeHTML(const URL, Host, Document : String): String;
+var
+ point :TPoint;
+ rect :TRect;
+begin
+ if (Pos('http://www.nicovideo.jp/watch/', URL) <> 1) then begin
+ Result := '<html><head>'#13#10
+ + '<SCRIPT>'#13#10
+ + 'function init() {'#13#10
+ + ' if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
+ + ' } else {'#13#10
+ + ' var dh, ih;'#13#10
+ + ' dh = document.body.clientWidth / document.body.clientHeight;'#13#10
+ + ' ih = Image1.width / Image1.height;'#13#10
+ + ' if (document.body.clientWidth < document.body.clientHeight) {'#13#10
+ + ' if (ih > dh)'#13#10
+ + ' Image1.width = document.body.clientWidth;'#13#10
+ + ' else'#13#10
+ + ' Image1.height = document.body.clientHeight;'#13#10
+ + ' } else {'#13#10
+ + ' if (ih < dh)'#13#10
+ + ' Image1.height = document.body.clientHeight;'#13#10
+ + ' else'#13#10
+ + ' Image1.width = document.body.clientWidth;'#13#10
+ + ' }'#13#10
+ + ' }'#13#10
+ + ' Message.style.display = "none";'#13#10
+ + '}'#13#10
+ + '</SCRIPT>'#13#10
+ + '</head>'#13#10
+ + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
+ + '<div align="center" id="Message">\83v\83\8c\83r\83\85\81[\8dì\90¬\92\86</div>'#13#10
+ + '<div align="center"><img name="Image1" border="0" src="' + URL + '"></div>'#13#10
+ + '</body></html>';
+ end else begin
+ // <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>
+ rect := GetWindowRect(point);
+
+ Result := '<html><head>'#13#10
+ + '<SCRIPT>'#13#10
+ + 'function init() {'#13#10
+ + ' Message.style.display = "none";'#13#10
+ + '}'#13#10
+ + '</SCRIPT>'#13#10
+ + '</head>'#13#10
+ + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
+ + '<div align="center" id="Message">\83v\83\8c\83r\83\85\81[\8dì\90¬\92\86</div>'#13#10
+ + '<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>'
+ + '</body></html>';
+ end;
+end;
+//! \83h\83L\83\85\83\81\83\93\83g\8a®\97¹\83C\83x\83\93\83g
+procedure TPreviewBrowser.BrowserDocumentComplete(Sender: TObject;
+ const pDisp: IDispatch; var URL: OleVariant);
+begin
+ if (URL <> 'about:blank') then begin
+ FEvent := THTMLDocumentEventSink.Create(Self, Self.OleObject.Document,
+ HTMLDocumentEvents2);
+ FEvent.OnDoubleClick := PreviewDbClick;
+ end else begin
+ if (FEvent <> nil) then begin
+ FreeAndNil(FEvent);
+ end;
+ end;
+end;
+function TPreviewBrowser.PreviewDbClick(Sender: TObject): WordBool;
+begin
+ // \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¤
+ PostMessage( GikoForm.Handle , USER_POPUPCLEAR, Integer( Self ), 0 );
+ Result := True;
end;
end.