00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JUCER_HEADER_BROWSERCONTENT_BROWSERCONTENT_A7439D3C__
00021 #define __JUCER_HEADER_BROWSERCONTENT_BROWSERCONTENT_A7439D3C__
00022
00023
00024 #include "../UZIBase.hpp"
00025
00026 #include "../URLChangeUpdater.hpp"
00027
00028 #include "../../HTMLParser/Parser.hpp"
00029
00030 #include "../../HTMLRenderer/GenericRenderer.hpp"
00031
00032 #include "../../CSSParser/CSSParser.hpp"
00033
00034 #include "../../Network/URLHandler.hpp"
00035
00036 #include "../DocumentFetcher.hpp"
00037
00038 #include "ErrorLogComponent.hpp"
00039
00040 #include "DOMTreeViewer.hpp"
00041
00042
00043
00044 namespace juce
00045 {
00046
00054 class BrowserContent : public Component
00055 , public HTML::Renderer::RequiredRendererImplementation
00056 {
00057 public:
00058
00059 BrowserContent (const String & browsedURL);
00060 ~BrowserContent();
00061
00062
00063
00064
00065 public:
00068 virtual CSS::Font * getDefaultFont();
00072 virtual CSS::Font * getBolderFont(CSS::Font * font);
00077 virtual CSS::Font * getScaledFont(CSS::Font * font, const float scale);
00083 virtual CSS::Font * getColouredFont(CSS::Font * font, const CSS::Colour & color);
00087 virtual CSS::Font * getItalicFont(CSS::Font * font);
00091 virtual CSS::Font * getMonospaceFont(CSS::Font * font);
00095 virtual uint32 getRenderedWidthOf(HTML::Renderer::Box * box);
00099 virtual uint32 getRenderedHeightOf(HTML::Renderer::Box * box);
00103 virtual uint32 getMinimumWidthOf(HTML::Renderer::Box * box);
00107 virtual uint32 getMinimumHeightOf(HTML::Renderer::Box * box);
00143 virtual bool getSplitLimitsOf(HTML::Renderer::Box * box, const int32 boxLeft, const int32 boxRight, const int32 top, const int32 left, int32 & right, int32 & bottom);
00162 virtual HTML::Renderer::TableLayout * getNewTableLayout(const HTML::Renderer::BoxHierarchy * box);
00169 virtual HTML::Renderer::TableLayout * getKnownTableLayout(const HTML::Renderer::BoxHierarchy * box);
00204 virtual bool getMinAndMaxWidthOf(HTML::Renderer::Box * box, int32 & minimumWidth, int32 & maximumWidth);
00205
00207 void drawSplitText(Graphics & g, HTML::Renderer::Box * box, juce::Justification just);
00208
00209
00210 bool loadTestDocument();
00211
00212 bool loadDocument();
00213
00215 inline juce::Colour convertFrom(const CSS::Colour & color) const { return juce::Colour(color.R, color.G, color.B, (uint8)(255 - (uint32)color.A)); }
00217 inline juce::String convertFrom(const DOM::DOMString & string) const { return juce::String::fromUTF8((const unsigned char*)string.getData(), string.getLength()); }
00218
00220 inline juce::Image * loadImage(const Strings::FastString & url) const;
00221
00227 int32 requiredHeightAfterRendering();
00228
00232 int fastWidgetArrayLookup(const HTML::Renderer::BoxHierarchy * box) const;
00233
00237 int fastLinkArrayLookup(const HTML::Renderer::BoxHierarchy * box) const;
00238
00242 const HTML::Renderer::BoxHierarchy * BrowserContent::linkHitTest(const Point & point) const;
00243
00244
00246 inline const String getSourceText()
00247 {
00248 if (!parser) return String::empty;
00249 if (!itemGroup) return String::empty;
00250
00251 volatile Cache::Item * item = holder.findItemFromURL(currentURL.asURI());
00252 if (!item) return String::empty;
00253 return String::fromUTF8((const uint8* const)item->getData(), item->getDataSize());
00254 }
00255
00257 inline void showErrors()
00258 {
00259 ErrorLogComponent component(parser, communicationHeaders);
00260 component.setSize(600, 400);
00261 DialogWindow::showModalDialog(JUCE_T("Error console"), &component, this, Colours::floralwhite, true, true, false);
00262 }
00263
00265 inline void showDOMTree()
00266 {
00267 DOMTreeViewer component(parser->getDOMTree());
00268 component.setSize(600, 400);
00269 DialogWindow::showModalDialog(JUCE_T("DOM Tree"), &component, this, Colours::floralwhite, true, true, false);
00270 }
00271
00273 void setUpdater(URLChangeUpdate * _urlUpdater) { urlUpdater = _urlUpdater; }
00274
00275
00276 void paint (Graphics& g);
00277 void resized();
00278 void visibilityChanged();
00279 void moved();
00280 void parentHierarchyChanged();
00281 void parentSizeChanged();
00282 void lookAndFeelChanged();
00283 bool hitTest (int x, int y);
00284 void broughtToFront();
00285 bool filesDropped (const StringArray& filenames, int mouseX, int mouseY);
00286 void handleCommandMessage (int commandId);
00287 void childrenChanged();
00288 void enablementChanged();
00289 void mouseMove (const MouseEvent& e);
00290 void mouseEnter (const MouseEvent& e);
00291 void mouseExit (const MouseEvent& e);
00292 void mouseDown (const MouseEvent& e);
00293 void mouseDrag (const MouseEvent& e);
00294 void mouseUp (const MouseEvent& e);
00295 void mouseDoubleClick (const MouseEvent& e);
00296 void mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
00297
00298
00299 void modifierKeysChanged (const ModifierKeys& modifiers);
00300 void focusGained (FocusChangeType cause);
00301 void focusLost (FocusChangeType cause);
00302 void focusOfChildComponentChanged (FocusChangeType cause);
00303 void inputAttemptWhenModal();
00304
00305
00306
00307 juce_UseDebuggingNewOperator
00308
00309 private:
00310
00312 HTML::Elements::Allocators::SimpleHeap elementAllocator;
00314 HTML::Renderer::Allocators::SimpleHeap boxAllocator;
00316 Stream::InputStream * IS;
00318 HTML::Parser * parser;
00320 HTML::Renderer::Mapper * mapper;
00321
00323 struct FontMap
00324 {
00326 juce::Font font;
00328 CSS::Font mappedFont;
00329
00331 FontMap(const juce::String & faceName, const float size, const uint32 UID, const CSS::Colour & color)
00332 : font(faceName, size, juce::Font::plain), mappedFont(new CSS::AbsoluteLength(size, CSS::AbsoluteLength::px), UID, color)
00333 { }
00335 ~FontMap() { delete mappedFont.size; }
00336 };
00337
00339 struct Widgets : public juce::ListBoxModel
00340 {
00342 juce::Component * component;
00344 const HTML::Renderer::BoxHierarchy * box;
00346 StringArray options;
00347
00349 Widgets(juce::Component * _component, const HTML::Renderer::BoxHierarchy * _box) : component(_component), box(_box)
00350 {}
00352 ~Widgets() { deleteAndZero(component); }
00353
00355 static inline int compareElements (const Widgets * first, const Widgets * second)
00356 {
00357 return first->box < second->box ? -1 : (first->box == second->box ? 0 : 1);
00358 }
00359
00361 virtual int getNumRows () { return options.size(); }
00362 virtual void paintListBoxItem (int rowNumber, Graphics &g, int width, int height, bool rowIsSelected)
00363 {
00364 g.fillAll(rowIsSelected ? LookAndFeel::getDefaultLookAndFeel().findColour(ListBox::backgroundColourId) : Colours::white);
00365 g.drawText(options[rowNumber], 0, 0, width, height, Justification::centredLeft, true);
00366 }
00367 };
00368
00370 struct LinkArea
00371 {
00373 Rectangle area;
00375 const HTML::Renderer::BoxHierarchy * box;
00376
00378 static inline int compareElements (const LinkArea * first, const LinkArea * second)
00379 {
00380 return first->box < second->box ? -1 : (first->box == second->box ? 0 : 1);
00381 }
00382
00383 LinkArea(const Rectangle & _area, const HTML::Renderer::BoxHierarchy * _box) : area(_area), box(_box)
00384 {}
00385 };
00386
00387
00388
00390 juce::OwnedArray<FontMap> fontArray;
00392 Network::URL currentURL;
00394 juce::OwnedArray<Widgets> widgetArray;
00396 typedef Tree::AVL::Tree<HTML::Renderer::TableLayout *, uint32, Comparator::DefaultComparator, Tree::AVL::PointerDeletion<HTML::Renderer::TableLayout *, uint32> > TableArray;
00398 TableArray tableLayoutArray;
00400 juce::OwnedArray<LinkArea> linksArray;
00401
00403 mutable Cache::Holder holder;
00405 UZI::DocumentFetcher fetcher;
00407 Cache::Holder::ItemGroup * itemGroup;
00409 String communicationHeaders;
00411 URLChangeUpdate * urlUpdater;
00412
00413
00414
00415
00416
00417
00418
00419 BrowserContent (const BrowserContent&);
00420 const BrowserContent& operator= (const BrowserContent&);
00421 };
00422
00423 }
00424
00425 #endif // __JUCER_HEADER_BROWSERCONTENT_BROWSERCONTENT_A7439D3C__