CString openTemporaryFile(const char* prefix, PlatformFileHandle& handle) { // BREW does not have a system-wide temporary directory, // use "fs:/~/tmp" as our temporary directory. String tempPath("fs:/~/tmp"); PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); // Create the temporary directory if it does not exist. IFILEMGR_MkDir(fileMgr.get(), tempPath.utf8().data()); // Loop until we find a temporary filename that does not exist. int number = static_cast<int>(randomNumber() * 10000); CString filename; do { StringBuilder builder; builder.append(tempPath); builder.append('/'); builder.append(prefix); builder.append(String::number(number)); filename = builder.toString().utf8(); number++; } while (IFILEMGR_Test(fileMgr.get(), filename.data()) == SUCCESS); IFile* tempFile = IFILEMGR_OpenFile(fileMgr.get(), filename.data(), _OFM_CREATE); if (tempFile) { handle = tempFile; return filename; } return CString(); }
static PlatformRefPtr<GdkCursor> createNamedCursor(CustomCursorType cursorType) { CustomCursor cursor = CustomCursors[cursorType]; PlatformRefPtr<GdkCursor> c = adoptPlatformRef(gdk_cursor_new_from_name(gdk_display_get_default(), cursor.name)); if (c) return c; const GdkColor fg = { 0, 0, 0, 0 }; const GdkColor bg = { 65535, 65535, 65535, 65535 }; IntSize cursorSize = IntSize(32, 32); PlatformRefPtr<GdkPixmap> source = adoptPlatformRef(createPixmapFromBits(cursor.bits, cursorSize)); PlatformRefPtr<GdkPixmap> mask = adoptPlatformRef(createPixmapFromBits(cursor.mask_bits, cursorSize)); return adoptPlatformRef(gdk_cursor_new_from_pixmap(source.get(), mask.get(), &fg, &bg, cursor.hot_x, cursor.hot_y)); }
void InspectorClient::populateSetting(const String& key, String* value) { if (shouldIgnoreSetting(key)) return; GSettings* settings = inspectorGSettings(); if (!settings) return; PlatformRefPtr<GVariant> variant = adoptPlatformRef(g_settings_get_value(settings, toGSettingName(key).utf8().data())); if (key == "resourceTrackingEnabled" || key == "xhrMonitor" || key == "debuggerEnabled" || key == "profilerEnabled") *value = truthStringFromVariant(variant.get()); else if (key == "frontendSettings") *value = String(g_variant_get_string(variant.get(), 0)); }
bool AccessibilityUIElement::isSelected() const { if (!ATK_IS_OBJECT(m_element)) return false; PlatformRefPtr<AtkStateSet> stateSet = adoptPlatformRef(atk_object_ref_state_set(ATK_OBJECT(m_element))); gboolean isSelected = atk_state_set_contains_state(stateSet.get(), ATK_STATE_SELECTED); return isSelected; }
bool getFileSize(const String& path, long long& result) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); FileInfo info; if (IFILEMGR_GetInfo(fileMgr.get(), path.utf8().data(), &info) == SUCCESS) { result = info.dwSize; return true; } return false; }
static void getDisplayInfo(DisplayInfo& info) { IDisplay* display = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIDisplay; PlatformRefPtr<IBitmap> bitmap = adoptPlatformRef(IDisplay_GetDestination(display)); AEEBitmapInfo bitmapInfo; IBitmap_GetInfo(bitmap.get(), &bitmapInfo, sizeof(AEEBitmapInfo)); info.width = bitmapInfo.cx; info.height = bitmapInfo.cy; info.depth = bitmapInfo.nDepth; }
static String canonicalPath(const String& path) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); // Get the buffer size required to resolve the path. int canonPathLen; IFILEMGR_ResolvePath(fileMgr.get(), path.utf8().data(), 0, &canonPathLen); // Resolve the path to the canonical path. Vector<char> canonPathBuffer(canonPathLen); IFILEMGR_ResolvePath(fileMgr.get(), path.utf8().data(), canonPathBuffer.data(), &canonPathLen); String canonPath(canonPathBuffer.data()); // Remove the trailing '/'. int lastDivPos = canonPath.reverseFind('/'); int endPos = canonPath.length(); if (lastDivPos == endPos - 1) canonPath = canonPath.substring(0, canonPath.length() - 1); return canonPath; }
String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const { ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); if (!mimeType.startsWith("image/")) return "data:,"; // List of supported image types comes from the GdkPixbuf documentation. // http://library.gnome.org/devel/gdk-pixbuf/stable/gdk-pixbuf-file-saving.html#gdk-pixbuf-save-to-bufferv String type = mimeType.substring(sizeof "image"); if (type != "jpeg" && type != "png" && type != "tiff" && type != "ico" && type != "bmp") return "data:,"; PlatformRefPtr<GdkPixbuf> pixbuf = cairoImageSurfaceToGdkPixbuf(m_data.m_surface); if (!pixbuf) return "data:,"; GOwnPtr<gchar> buffer(0); gsize bufferSize; GError* error = 0; gboolean success = FALSE; if (type == "jpeg" && quality && *quality >= 0.0 && *quality <= 1.0) { String qualityString = String::format("%f", *quality); success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error, "quality", qualityString.utf8().data(), NULL); } else { success = gdk_pixbuf_save_to_buffer(pixbuf.get(), &buffer.outPtr(), &bufferSize, type.utf8().data(), &error, NULL); } if (!success) return "data:,"; Vector<char> out; base64Encode(reinterpret_cast<const char*>(buffer.get()), bufferSize, out); out.append('\0'); return String::format("data:%s;base64,%s", mimeType.utf8().data(), out.data()); }
void Pasteboard::writeImage(Node* node, const KURL&, const String&) { GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD); ASSERT(node && node->renderer() && node->renderer()->isImage()); RenderImage* renderer = toRenderImage(node->renderer()); CachedImage* cachedImage = renderer->cachedImage(); if (!cachedImage || cachedImage->errorOccurred()) return; Image* image = cachedImage->image(); ASSERT(image); PlatformRefPtr<GdkPixbuf> pixbuf = adoptPlatformRef(image->getGdkPixbuf()); DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); dataObject->setImage(pixbuf.get()); m_helper->writeClipboardContents(clipboard); }
FontPlatformData::FontPlatformData(FcPattern* pattern, const FontDescription& fontDescription) : m_pattern(pattern) , m_fallbacks(0) , m_size(fontDescription.computedPixelSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_fixedWidth(false) { PlatformRefPtr<cairo_font_face_t> fontFace = adoptPlatformRef(cairo_ft_font_face_create_for_pattern(m_pattern.get())); initializeWithFontFace(fontFace.get()); int spacing; if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) == FcResultMatch && spacing == FC_MONO) m_fixedWidth = true; if (fontDescription.weight() >= FontWeightBold) { // The FC_EMBOLDEN property instructs us to fake the boldness of the font. FcBool fontConfigEmbolden; if (FcPatternGetBool(pattern, FC_EMBOLDEN, 0, &fontConfigEmbolden) == FcResultMatch) m_syntheticBold = fontConfigEmbolden; } }
bool deleteEmptyDirectory(const String& path) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); return (IFILEMGR_RmDir(fileMgr.get(), path.utf8().data()) == SUCCESS); }
bool fileExists(const String& path) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); return (IFILEMGR_Test(fileMgr.get(), path.utf8().data()) == SUCCESS); }
bool makeAllDirectories(const String& path) { PlatformRefPtr<IFileMgr> fileMgr = createRefPtrInstance<IFileMgr>(AEECLSID_FILEMGR); return makeAllDirectories(fileMgr.get(), canonicalPath(path)); }
static PlatformRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot) { IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot); PlatformRefPtr<GdkPixbuf> pixbuf = adoptPlatformRef(image->getGdkPixbuf()); return adoptPlatformRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y())); }