interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- ActiveX,
+ ActiveX, OleCtrls, HTMLDocumentEvent,
{$IF Defined(DELPRO) }
- SHDocVw
+ SHDocVw,
+ MSHTML
{$ELSE}
- SHDocVw_TLB
+ 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
end;
implementation
-uses MojuUtils, GikoSystem, Setting;
+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);
begin
inherited Create(AOwner);
+ FEvent := nil;
+ OnDocumentComplete := BrowserDocumentComplete;
end;
destructor TPreviewBrowser.Destroy;
begin
+ if (FEvent <> nil) then begin
+ FreeAndNil(FEvent);
+ end;
inherited Destroy;
end;
}
procedure TPreviewBrowser.PreviewImage(URL : String);
var
- html : string;
HtmlFileName : string;
sl : TStringList;
Protocol, Host, Path, Document, Port, Bookmark : string;
PostData: OleVariant;
Headers: OleVariant;
begin
- html := '<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="%ImageURL%"></div>'#13#10
- + '</body></html>';
-
+ 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 := MojuUtils.
- CustomStringReplace(html, '%ImageURL%', URL, False);
+ sl.Text := makeHTML(URL, Host, Document);
sl.SaveToFile(HtmlFileName);
finally
sl.Free;
except
end;
- 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 := '';
Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
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
- gppRightTop: OffsetRect(Result,
- Point.x - (Result.Right - Result.Left) - 15, Point.y - (Result.Bottom - Result.Top) - 15);
- gppRight: OffsetRect(Result,
- Point.x - (Result.Right - Result.Left) - 15, Point.y - ((Result.Bottom - Result.Top) div 2));
- gppRightBottom: OffsetRect(Result,
- Point.x - (Result.Right - Result.Left) - 15, Point.y + 15);
+ 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 - ((Result.Right - Result.Left) div 2), Point.y - (Result.Bottom - Result.Top) - 15);
+ Point.x - (WindowWidth div 2), Point.y - WindowHeight - DIV_Y);
gppCenter: OffsetRect(Result,
- Point.x - ((Result.Right - Result.Left) div 2), Point.y - ((Result.Bottom - Result.Top) div 2));
+ Point.x - (WindowWidth div 2), Point.y - (WindowHeight div 2));
gppBottom: OffsetRect(Result,
- Point.x - ((Result.Right - Result.Left) div 2), Point.y + 15);
- gppLeftTop: OffsetRect(Result,
- Point.x + 15, Point.y - (Result.Bottom - Result.Top) - 15);
- gppLeft: OffsetRect(Result,
- Point.x + 15, Point.y - ((Result.Bottom - Result.Top) div 2));
- gppLeftBottom: OffsetRect(Result, Point.x + 15, Point.y + 15); //\83M\83R\83i\83r\83X\83\8c \83p\81[\83g\82P\82Ì453\8e\81\82É\8a´\8eÓ
+ 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.